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?

============

$limit=5;
$numresult=mysql_query($select . $from . $where . $order);
$numrows=mysql_num_rows($numresult);

if(empty($offset)) {
$offset=0;
}

$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) {
$prevoffset=$offset-5;
print "<a href=\"$PHP_SELF?offset=$prevoffset&email=$email\">prev</a>&nbsp;\n";

}

$pages=intval($numrows/$limit);

if ($numrows%$limit) {
$pages++;
}

for ($i=1;$i<=$pages;$i++) {
$newoffset=$limit*($i-1);

if($i==($offset/$limit)+1)
{
print "$i&nbsp; \n";
}
else
{

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

====================

Thanks,
Willow

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 www.crm4sme.com (the search part is under the section expertise and you'll see why I need next/prev links!)... you'll have to register though :-)