Forum Moderators: coopster

Message Too Old, No Replies

pagination problem

cannot get results pass to next page

         

foodstyling

2:28 pm on Feb 15, 2004 (gmt 0)

10+ Year Member



Hi,
I try to make a pagination system work on a page of results that come from a form. The results get fine to the results page (with the right limit specification, but I am unable to pass the following results to next page. I think the problem could be on two places:

Or I made a mistake in my form which looks like this:

<form method=POST action= "results.php">
<SELECT NAME = "catID" SIZE = "1">
<?

$query= " SELECT catID, catName FROM categories ORDER BY catID";

$result = mysql_query($query);

while($catID =mysql_fetch_array($result))
{
print("<OPTION VALUE =\"$catID[0]\">$catID[1]\n");

}
?>
</select><br><br>
Vul hier een ingredient in:<br><br>
<input name = "ingredienten" type = text>
<input type="submit" value= "zoek!">
<input type = "reset" value= "zoek opnieuw!">
</form>

or I cannot paas the results because I use two different tables in the query: the tablenames are 'categories' and 'recepten'

the queries on the results page look like this:

$numresults = mysql_query_test("SELECT recept AS RECEPTEN FROM recepten WHERE ingredienten LIKE
'%" . $param1 . "%' AND catID = ('$catID') "); // the query.

$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.

and

$sql = mysql_query_test("SELECT recept AS RECEPTEN FROM recepten WHERE ingredienten LIKE
'%" . $param1 . "%' AND catID = ('$catID') ORDER BY recept limit $page, $limit ");

while ($row = mysql_fetch_array($sql)) {
$recept = $row['recept'];
echo $row['recept'] ."<br />";

and I try to link to next page with this:

if ($page!= 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"results.php?<?php echo(SID);?ingredienten=$param1&catId=$catID&page=$back_page&limit=$limit\">vorige</a>   \n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit * ($i - 1);
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"results.php?<?php echo(SID);?ingredienten=$param1&catID=$catID&page=$ppage&limit=$limit\">$i</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages!= 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"results.php?<?php echo(SID);?ingredienten=$param1&catID=$catID&page=$next_page&limit=$limit\">volgende</a>");}
?>

I makes me mad that I cannot get it right. Can someone help?

foodstyling

justageek

2:39 pm on Feb 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't look through all the code yet but what do you see when you print out:

print("<OPTION VALUE =\"$catID[0]\">$catID[1]\n");

The values are probably not what you expect. Try:

while($catrs =mysql_fetch_array($result))
{
print("<OPTION VALUE =\"".$catrs['catID']."\">".$catrs['CatName']."\n");

}

JAG

foodstyling

2:45 pm on Feb 15, 2004 (gmt 0)

10+ Year Member



In fact they do ok, the form is dynamic and gives rhe right choices for my categories. I was wondering in fact if I should not use something like a hidden value to send the results from the categories choice to the second part of the form wich is a text search. Couldn't I than make only 1 query in the results page? Maybe this is stupid, but I am realyy new in thist php stuff.