- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
<?php
require_once("inc/mysql.php");
sleep(3); //Для ajax запроса, потом удалить
// Проверяем, что к нам идёт Ajax запрос
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$city1 = $_POST['city1'];
}else{
exit(); // Заканчиваем работу скрипта, если это не ajax запрос
}
if (isset($city1)) {
$query = "SELECT id_city, id_region, id_country FROM cities WHERE city_name_ru LIKE '$city1'";
$result = mysqli_query($link, $query);// or trigger_error(mysql_error($link)." ".$query);
$row = mysqli_fetch_array($result);
$country = $row['id_country'];
//echo $country;
//echo '<br>';
$region = $row['id_region'];
//echo $region;
//echo '<br>';
$query1 = "SELECT country_name_ru FROM countries WHERE id_country = '$country'";
$result1 = mysqli_query($link, $query1);// or trigger_error(mysql_error($link)." ".$query);
$row1 = mysqli_fetch_array($result1);
echo '<p class=\'country\'>Страна '.$row1['0'].'</p>';
//echo '<br>';
$query2 = "SELECT region_name_ru FROM regions WHERE id_region = '$region'";
$result2 = mysqli_query($link, $query2);// or trigger_error(mysql_error($link)." ".$query);
$row2 = mysqli_fetch_array($result2);
echo '<p class=\'reqion\'>Область '.$row2['0'].'</p>';
}
?>