<?php
include 'connectsqli.php';
$country=mysqli_real_escape_string($con,trim($_GET['country']));
$city=mysqli_real_escape_string($con,trim($_GET['city']));
$tableName="user";
$targetpage = "result_members.php";
$limit = 2;
$search ="";
$search .= " WHERE country LIKE '".$country."' AND city LIKE '".$city."'";
$query = mysqli_query($con,"SELECT COUNT(*) as num FROM $tableName ".$search);
$total_pages = mysqli_fetch_array($query);
$total_pages = $total_pages['num'];
$page = mysqli_escape_string($con,$_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName ".$search." LIMIT $start, $limit";
$result = mysqli_query($con,$query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = "";
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Next
if ($page < $lastpage){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
?>
<?php
while($row = mysqli_fetch_assoc($result))
{
//display data
}
echo "<div class='pagee'>".$paginate."</div>";
?>
我是PHP和MySQLi的新手。这是我的搜索结果页面。
它适用于第一页,当我点击下一页时,它无效......
我在google上搜索,有些人说我需要使用http_build_query
来存储$country
和$city
的变量。
任何人都可以帮我解决这个问题吗?