I found this old article http://www.phpbuilder.com/columns/rod20000221.php3 on a google search and with some modifying was able to make most of it work for me. The one thing that doesn't want to work is not showing the next button on the last page. (the next button is always there, even on the last page) Anyone have any suggestions?
Here is my modified code:
<?php
//Gets offset from URL
$offset = $_GET["offset"];
// Setting Limit
$limit=20;
// Finding number of rows
$numr="select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER";
$numresults=odbc_exec($conn,$numr);
$numrows=odbc_num_rows($numresults);
// determine if offset has been passed to script, if not use 0 (is this needed?)
if (empty($offset)) {
$offset=0;
}
//Change limit maximum to increase based on offset
$limitO=$limit+$offset;
// get results
$sql="select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER $offset,$limitO";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
while (odbc_fetch_row($rs))
{
//display results
}
// next we need to do the links to other results
if ($offset>=1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
?>
Thanks.