/**************************************************************************************************************/
/* Description: This snippet is to provide you a simple way you can create autocomplete */
/* suggestions for different region, city locations across the country. */
/* There are 2 steps in this snippet. For information, please visit IP2Location tutorial page at:*/
/* https://www.ip2location.com/tutorials/creating-autocomplete-for-city-search-using-php-and-mysql-database */
/**************************************************************************************************************/
/* You can obtain free IPV6 database at https://www.ip2location.com/free/ipv6 */
City Search Example Code Auto Complete
City Search Example Code Auto Complete
Step 2: Create fetch.php file
0){
while($row = mysqli_fetch_assoc($result)){
$data[] = $row["region_name"];
}
echo json_encode($data);
}
}else{
//select the city name based on the user input
//retrieve the country name from index.php
$country_code = $_POST['country_code'];
//retrieve user input to do autocomplete
$request = mysqli_real_escape_string($connect, $_POST["query1"]);
$region_name = mysqli_real_escape_string($connect, $_POST["region_name"]);
$query = "select DISTINCT city_name from ip2location_db3 where country_code = '".$country_code."' AND region_name = '".$region_name."' AND city_name LIKE '{$request}%' GROUP BY city_name";
$result = mysqli_query($connect, $query);
$data = array();
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$data[] = $row["city_name"];
}
echo json_encode($data);
}
}
?>