{Passing a Query with PREV / NEXT
Hello,
I use the following PREV / NEXT code:
PHP Code:
// get results
$result=mysql_query("select * from gtex where ID>1000 order by ID limit $offset,$limit");
// now you can display the results returned
$i = 1;
echo (' <div align="center"> <table border="0" cellpadding="4" cellspacing="0" width="100%"> ');
while ( $row = mysql_fetch_array( $result ) )
{
extract($row);
echo ('<tr>');
echo ("<td width='33%'><a href=../print_resume.php?ID=$ID target='_blank' style='color: #000080'><font face='Verdana' size='1'>$name</font></a></td>
");
echo ('<td width="45%"><font face="Verdana" size="1">'.$row["description"].'</font></td>');
echo ("<td width='22%' align='right'><a href=../mycoverletter.php?ID=$ID target='_blank' style='color: #CC3300'><font face='Verdana' size='1'>See
Cover Letter</font></a></td>");
echo ('</tr>');
$i++;
}
echo "</table>";
// 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";
}
?>
The code works fine when I use this query :
PHP Code:
select * from gtex where ID>1000 order by ID
But I want to use this query: (Before displaying the results, I want to give my users the possibility to choose search criteria : $category and $state)
PHP Code:
if($category<>"0" and $state<>"0"){
$condition = "state='$state' and category='$category'";
}
if($category<>"0" and $state =="0" ){
$condition = "category='$category'" ;
}
// My Query
$result=mysql_query("SELECT * FROM gtex WHERE $condition limit $offset,$limit");
When I use the PREV / NEXT code with this query, it works for page #1, but the query is not passed on the other pages.
What should I do to make it work for all the pages?
Thank you !