Php 分页错误
显示ASC到DESC的分页为:Php 分页错误,php,pagination,Php,Pagination,显示ASC到DESC的分页为: if($page == 1) { $pstart = 0; } else { $pstart = $page * $totalrows; } $pend = $pstart + $totalrows; HTML代码是从ASC到DESC的 <form action="<?=$_SERVER["SCRIPT_NAME"];?>" method="get"> <div> <a class="page-num
if($page == 1) { $pstart = 0; } else { $pstart = $page * $totalrows; }
$pend = $pstart + $totalrows;
HTML代码是从ASC到DESC的
<form action="<?=$_SERVER["SCRIPT_NAME"];?>" method="get">
<div>
<a class="page-numbers" href="<?=$_SERVER["SCRIPT_NAME"];?>?p=<?=$page + 1;?>">Next</a>
<input class="page-numbers" name="p" type="text" value="<?=$page + 1;?>" /> <input class="page-numbers" type="submit" value="Jump" />
</div>
</form>
我应该更改哪些php代码,因为要显示ASC POST的DESC和显示接下来10篇POST的分页,请更改限制部分(语法为限制偏移,行计数)
您可以使用sqllimit命令将自己限制为10个结果并传递一个偏移量。 另外,您的代码
if($page==1){$pstart=0;}否则{$pstart=$page*$totalrows;}
$pend=$pstart+$totalrows代码>
不正确-对于第1页,$pstart将为0,但是对于第2页,$sptart将为20,使您跳过记录10-19
$sql = "SELECT posts.Tags as tags, posts.OwnerUserId as postsid, posts.Id as postid, posts.Body as body, posts.Title as title, users.Id as userid, users.DisplayName as usersname FROM posts JOIN users ON posts.OwnerUserId = users.Id WHERE posts.Id >= " . $pstart . " AND posts.Title != '' ORDER by posts.Id DESC LIMIT " . $totalrows;
$sql = "SELECT posts.Tags as tags, posts.OwnerUserId as postsid, posts.Id as postid, posts.Body as body, posts.Title as title, users.Id as userid, users.DisplayName as usersname FROM posts JOIN users ON posts.OwnerUserId = users.Id WHERE posts.Id >= " . $pstart . " AND posts.Title != '' ORDER by posts.Id DESC LIMIT " . (($page-1) * $totalrows) .",". $totalrows;