Hi everyone,
I have some php code which retrieves data from an Access db and lists the results which are then paginated to 15 entries per page.
All works fine except that the first page only returns 14 values, with the first db not being displayed (ie. for 100 entries it only displays 99). The first part of the code determining the results per page:
$page = $_GET["page"];
if($page == ""){
$page = 1;
}
$maxResults= 15;
$from = (($page * $maxResults) - $maxResults);
$max = ($page * $maxResults);
$eventsTotal = "select * from Events $sqlKeywds ORDER by $orderA";
This is followed by the retrieve/display code:
$rs = odbc_exec($conn, $eventsTotal) or die (odbc_errormsg());
if(!odbc_fetch_row($rs)){
exit ("<b>No Records Found</b></br>");}
$i=0;
while (odbc_fetch_row($rs)){
if (($i>=$from) and ($i<$max)){
$id=odbc_result($rs, "ID");
$name=odbc_result($rs, "Name");
$date=odbc_result($rs, "DateA");
$loc=odbc_result($rs, "Loc");
$cat=odbc_result($rs, "Cat");
$formattedDate = date("d/m/Y", strtotime($date));
$formattedTime = date("h:i A", strtotime($date));
echo "<tr><td><font face='Verdana, arial' size='1'><a href=\"eventEdit.php?ID= $id\">Edit</a> <a href=\"delete.php?ID= $id\">Remove</a></font></td>";
echo "<td bgcolor='$col1'><font face='Verdana, arial' size='1'>$name</font></td>";
echo "<td bgcolor='$col2'><font face='Verdana, arial' size='1'>$formattedDate <br />$formattedTime</font></td>";
echo "<td bgcolor='$col1'><font face='Verdana, arial' size='1'>$loc</font></td>";
echo "<td bgcolor='$col2'><font face='Verdana, arial' size='1'>$cat</font></td></tr>";
if($bg == 1){
$col1 = "#eeeeee";
$col2 = "#dddddd";
$bg = 0;
}
elseif($bg == 0){
$col1 = "#cccccc";
$col2 = "#bbbbbb";
$bg = 1;
}
}
++$i;
}
I have left out some code to make it easier to follow (hopefully!). I have tried changing the i value to 1 and -1 but this returned 15 rows on the first page but only 9 on the last (ie. still 99) and 16 rows/page respectively.
Can anyone help with this?
Thanks.