I am looking at some legacy code and would like some assistance on a few things.
All of my questions relate to pagination.
First, in the following query, we are calculating the total number of pages. $itemsperpage=40 here
.
$rs0=mysqli_fetch_array(mysqli_query($dbh,"select floor(count(1)/$itemsperpage)+1 as pages from scx_media where scx_media.mediaid in (select mediaid from animated_gifs where status>0)"));
Why do we floor this, and then add 1?
Secondly,
In this piece of code we create the start variable (to be used in sql query).
$page=(int)$_GET['page'];
$pages=$rs0[pages];
if($page>$pages)$page=$pages;
$start=($page-1)*$itemsperpage;
Why do we minus one from the page? Because we start at 0 so we must minus 1?
And finally,
Let's say that we have 40 items
and the perpage item count is 40 as well
. With this configuration,we'd have a second page with no data
because it would display the 40 items on the first page which meets the per page requirement and then according to the pages calculation we'd have a second page but there would be no records. How do I resolve that issue?