我的分页有问题,它可以正常工作,但是当我点击例如
我有搜索 ermel ermel 有 8 个字段,它会输出分页,因为限制设置为每页 5 个
[1][2]
但是当我点击第二页时,它会转到另一页并删除我的查询。
并将再次计算我的整个查询
[1][2][3][4][5][6]
像那样,并将重置为可能的默认查询
我不确定错误在哪里 - 我试图删除某些部分,但这是唯一不能正常工作的部分,谢谢。
这是我的工作 php 代码。
<?php
$searchtext = '';
if(isset($_GET['q'])) $searchtext = mysql_real_escape_string($_GET['q']);
if($searchtext) {
$per_page =5;
$pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons where firstname like '%$searchtext' or lastname like '%$searchtext' order by date desc ");
$pages = ceil(mysql_result($pages_query,0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query=mysql_query("select * from persons where firstname like '%$searchtext' or lastname like '%$searchtext' order by date desc LIMIT $start,$per_page ");
}
else
{
$per_page =5;
$pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons ");
$pages = ceil(mysql_result($pages_query,0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query=mysql_query("select * from persons order by date desc LIMIT $start,$per_page ");
}
while($test = mysql_fetch_array($query))
{
$id = $test['PersonID'];
echo"<div class = content />";
echo "<table>
<tr>
<td rowspan='2'><img height=200 width=200 src='upload/". $test['Image'] ."'/></td>
<td><a href ='profile.php?PersonID=$id'>".$test['LastName'].", ". $test['FirstName']." ". $test['MiddleName']."</a>
</tr>
<tr>
<td><a href ='user_edit_reports.php?PersonID=$id'><input type='submit' name='submit' value='Edit'/></a>
</tr>
</table>";
echo"</div>";
}
if ($pages >=1 && $page <= $pages) {
for ($x=1; $x<=$pages; $x++) {
echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.' </a></strong>' : '<a href="?page='.$x.'">'.$x.' </a>';
}
}
?>