-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_back.php
65 lines (47 loc) · 1.88 KB
/
6_back.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
// debug
// VAR_DUMP($_POST);
include('db.php');
$link = connect();
$country_search = "";
if ( isset($_POST['country']) ) $country_search = mysqli_escape_string($link, $_POST['country']);
else $country_search = "0";
if ( isset($_POST['page']) )
$page = $_POST['page'];
else $page = 0;
echo "<input type='hidden' id='nonopage' name='nonopage' value='".$page."'>";
if ( $country_search != "" ) {
// output cities of selected country
// calcs for pagination
$total_query = "SELECT count(`test_cities`.`name`) FROM `test_cities` RIGHT JOIN `test_countries` ON `test_countries`.`id` = `test_cities`.`country_id` WHERE `test_countries`.`name` like '%".$country_search."%'";
$q_cities = mysqli_query($link, $total_query);
$r_cities = mysqli_fetch_row($q_cities);
$num_cities = $r_cities[0];
$num_pages = ceil($num_cities / 5);
$full_pages = $num_cities / 5;
$ostat = $num_cities - ($num_pages * 5);
$from = $page*5;
$limit = min($num_cities-($page*5), 5);
$query = "SELECT `test_cities`.`name` FROM `test_cities` RIGHT JOIN `test_countries` ON `test_countries`.`id` = `test_cities`.`country_id` WHERE `test_countries`.`name` like '%".$country_search."%' LIMIT ".$from.", ".$limit;
$result = mysqli_query($link, $query);
if ( !$result ) echo "Fault";
echo "<table>".
"<th>Город</th>";
while ( $row = mysqli_fetch_row($result) )
{
echo "<tr><td>".$row[0]."</td></tr>";
}
echo "</table>";
if ( $num_pages > 1) {
$prev_page=max(0,$page-1);
$next_page=min($num_pages-1, $page+1);
echo "<button id='button_1' name='page' value=".$prev_page.">Предыдущие</button> ";
echo "<button id='button_1' name='page' value=".$next_page.">Следующие</button><br />";
$page_to_show = $page+1;
echo "Страница ".$page_to_show." из ".$num_pages."";
};
}; // if country
//var_dump($_POST);
//var_dump($country_search);
close_db($link);
?>