修改分页脚本以在第一页上显示与其他页不同的行数


Modify pagination script to show a different number of rows on the first page than the others

我有一个简单的分页脚本:

$product_nr = count($query); // counts the number of products
$totalpages = ceil($product_nr / $rowsperpage);  
if ($currentpage > $totalpages){ $currentpage = $totalpages; } 
$offset = (($currentpage - 1) * $rowsperpage);

代码设置为每页显示20行->$rowsperpage=20;

我需要一个如何在第一页仅显示18行的想法,并将剩余的2行添加到$product_nr中,这样就不会阻碍其他页面每页20行的分页。

基本上:

1st page - 18 rows;
the other pages would show 20 rows per page from the remaining rows.

有什么想法吗?

如果可能,您可以设置$在第一页时每页单独一行,即如果$currentpage==1,则$rowperpage=18对于所有其他页面,您必须将偏移量设置为-2即

if($currentpage!=1){$offset=((($currentpage-1)*$rowsperpage))-2;}

if($currentpage == 1)
$rowsperpage = 18;
else
$rowsperpage = 20;