Help me out guys. I am probably being such a bonehead but I can't figure out where I've gone wrong with this code for adding Next/Prev buttons to my pages:
$
ID = $_GET;
$limit=2; // rows to return
$numresults=mysql_query("SELECT * from fragrances WHERE ID=$ID ORDER BY title");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=0;
}
// get results
$result=mysql_query("ima_link, title, size, rrp, £, SHO, cli_link, buy_link ".
"from fragrances WHERE ID=$ID ".
"ORDER BY title LIMIT $offset,$limit");
// now you can display the results returned
echo "<table border='0' cellpadding='5' cellspacing='0' width='500'>";
while($row = mysql_fetch_array( $numresults )) {
// Print out the contents of each row into a table
echo "<tr><td align='center' bgcolor='#ffffff' rowspan='2' valign='top' width='125'>";
echo $row;
echo "</td><td align='center' bgcolor='#ffffff' valign='top' width='250'><p class='main_title'>";
echo $row;
echo "</p></td><td align='center' bgcolor='#ffffff' rowspan='2' valign='top' width='125'><p class='main_type'>";
echo $row . " ". $row;
echo "</p><p class='main_rrp'>RRP £";
echo $row;
echo "</p><p class='main_£'>DFUK £";
echo $row;
echo "</p><p class='main_shop'>";
echo $row;
echo "</p><p class='main_buttons'>";
echo $row . $row;
echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' valign='top' width='250'><p class='main_manufacturer'>";
echo $row;
echo "</p></td></tr><tr><td align='center' bgcolor='#ffffff' colspan='3' valign='top' width='500'><hr color='#999999' width='95%'></hr>";
echo "</td></tr>";
}
echo "</table>";
// include code to display results as you see fit
// 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";
}
?>
I've obviously left out the connection details for privacy and I know the table syntax is abysmal. i'm just trying to sort out the large functionality before i tackle the smaller issues. lol.
What appears to be wrong is the $limit and the subsequent offset pages. Here's an example for you all to muster over. You can see the limit is not reduced to "2" like it's supposed to be.