Below is the code I'm using for next/previous links for the output of a search.

It works on the first page that comes up, e.g. there are 18 results, with a limit of 5, I get the following links

1 2 3 4 next

But when either the "next" link or the page number link is clicked, the page with the next 5 results gives me all the rows (30) in the database (as if the where clause isn't taken into consideration)

prev 1 2 3 4 5 6 next

And when I click "1" or "previous" I also get all the rows.

Anyone know what's wrong with the following code?


$numresult=mysql_query($select . $from . $where . $order);

if(empty($offset)) {

$limits = " LIMIT $offset,$limit";

$result=mysql_query($select . $from . $where . $order . $limits);

if (!$result) {
echo ("<P> error retrivieving partners from database!<br>".
"Error: " . mysql_error());
exit ();

//prev/next links

if (!$offset==0) {
print "<a href=\"$PHP_SELF?offset=$prevoffset&email=$email\">prev</a>&nbsp;\n";



if ($numrows%$limit) {

for ($i=1;$i<=$pages;$i++) {

print "$i&nbsp; \n";

print "<a href=\"$PHP_SELF?offset=$newoffset&email=$email\">$i</a> &nbsp; \n";
if (!(($offset/$limit)==$pages-1) && $pages!=1) {
print "<a href=\"$PHP_SELF?offset=$newoffset&email=$email\">next</a><p>\n";



PS: this is almost the last thing I have to do to complete the site. If you're interested in seeing the work of a newbie go to (the search part is under the section expertise and you'll see why I need next/prev links!)... you'll have to register though :-)