I have a form with a search box on one page and a processing script (most of which is below) which returns teh results based on the search. What's funny is that the first page of the results is correct, but when I click the "next page" link, it displays what seems like random data and not the second result set...am I missing soething in my code? Thanks for your help!

PHP Code:
              <?php

                        $sql 
"select distinct drinkid from ingredients where ingredient like '%$search%'";

                        
$result mysql_query($sql ,$db);
                        
$numrows mysql_numrows($result);

                        
$lastpage false;

                        if (
$pagenum == 0) {
                           
$startrow 0;
                        } else {
                           
$startrow 25 $pagenum;
                        }

                        if (
$numrows $startrow 25) {
                           
$endrow $numrows;
                           
$lastpage true;
                        }

                        
$sql "select distinct drinkid from ingredients where ingredient like '%$search%' limit $startrow,25";

                        
$result mysql_query($sql ,$db);

                        
$drinkcount 1;

                        if (
$myrow mysql_fetch_array($result)) {

                           do {

                              
$drinkid[$drinkcount] = $myrow["drinkid"];
                              
$drinkcount++;

                           } while (
$myrow mysql_fetch_array($result));

                        }

                        if (
count($drinkid) == 0) {

                           
printf("<tr><td colspan=3><p><center><FONT face=arial size=2><b>No Results Found</b></font></center></p></td></tr>");

                        } else {

                           
$rowcolor 1;

                           for (
$d 1$d <= count($drinkid); $d++) {

                                 
$sql "select drinkid, title, date, rating, status from drinks where drinkid = $drinkid[$d] order by title";

                              
$result mysql_query($sql ,$db);

                              if (
$myrow mysql_fetch_array($result)) {

                                 do {

                                    if (
$myrow["status"] == "L") {

                                       if (
$rowcolor == 1) {
                                          
$rowcolorhex "#ECE8D7";
                                          
$rowcolor 0;
                                       } else {
                                          
$rowcolorhex "#ded7bc";
                                          
$rowcolor 1;
                                       }


                                       
printf("<tr>");
                                       
printf("<td width=300 bgcolor=%s align=center><a href=drink.php?drinkid=%s class=\"linktable\">%s</a></td>"$rowcolorhex$myrow["drinkid"], $myrow["title"]);
                                       
printf("<td width=80 bgcolor=%s align=center><FONT face=verdana size=2>%s</font></td>"$rowcolorhex$myrow["date"]);
                                       
printf("<td width=75 bgcolor=%s><table bgcolor=%s border=0 cellspacing=0 cellpadding=0><tr>"$rowcolorhex$rowcolorhex);

                                       
$onstars round($myrow["rating"]);
                                       
$offstars $onstars;

                                       for (
$i 1$i <= $onstars$i++) {
                                          
printf("<td width=15 bgcolor=%s align=center valign=center><FONT face=arial size=2><img src=images/staron2.gif></font></td>"$rowcolorhex);
                                       }

                                       for (
$f 1$f <= $offstars$f++) {
                                          
printf("<td width=15 bgcolor=%s align=center valign=center><FONT face=arial size=2><img src=images/staroff2.gif></font></td>"$rowcolorhex);
                                       }

                                       
printf("</tr></table></td>");
                                       
printf("</tr>");

                                    }

                                 } while (
$myrow mysql_fetch_array($result));

                              }

                           }
                        }

                        
printf("<tr>");
                        if (
$startrow 0) {
                           
printf("<td align=left><FONT face=verdana size=2><a href=results.php?pagenum=%s&search=%s>Previous Page</a></font></td>"$pagenum-1$search);
                        } else {
                           
printf("<td>&nbsp;</td>");
                        }
                           
printf("<td>&nbsp;</td>");
                        if (
$lastpage == false) {
                           
printf("<td align=left><a href=results.php?pagenum=%s&search=%s class=\"linktable\">Next Page</a></td>"$pagenum+1$search);
                        } else {
                           
printf("<td>&nbsp;</td>");
                        }
                        
printf("</tr>");



                     
?>