Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 分页错误_Php_Pagination - Fatal编程技术网

Php 分页错误

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

显示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-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;