?
| Current Path : /home/webyoo/www/leumi/site/ |
| Current File : /home/webyoo/www/leumi/site/autocomplete_locations.php |
<?php
include "start.php";
$term = isset($_GET['term']) ? mysqli_real_escape_string($link, $_GET['term']) : '';
$results = [];
if ($term !== '') {
$query = mysqli_query($link, "
SELECT name_property, region, city
FROM rent_properties
WHERE status = 3
AND (
name_property LIKE '%" . $term . "%'
OR region LIKE '%" . $term . "%'
OR city LIKE '%" . $term . "%'
)
ORDER BY city, region, name_property
LIMIT 20
");
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
// Ajouter city
if (!empty($row['city']) && stripos($row['city'], $term) !== false) {
$label = $row['city'];
if (!in_array($label, array_column($results, 'value'))) {
$results[] = ['label' => $label, 'value' => $label];
}
}
// Ajouter region
if (!empty($row['region']) && stripos($row['region'], $term) !== false) {
$label = $row['region'];
if (!in_array($label, array_column($results, 'value'))) {
$results[] = ['label' => $label, 'value' => $label];
}
}
// Ajouter name_property
if (!empty($row['name_property']) && stripos($row['name_property'], $term) !== false) {
$label = $row['name_property'];
if (!in_array($label, array_column($results, 'value'))) {
$results[] = ['label' => $label, 'value' => $label];
}
}
}
}
header('Content-Type: application/json');
echo json_encode($results);