ds111 Posted March 30, 2008 Share Posted March 30, 2008 hey guys so im doing pagination...What am i doing wrong? heres my code: //Begin Pagination if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if $query = "SELECT count(*) FROM restaurants WHERE type='$type'"; $result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $rows_per_page = 15; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // if if ($pageno < 1) { $pageno = 1; } // if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT * FROM restaurants WHERE type='$type' $limit"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $num = mysql_numrows($query); $index = 0; while($num != $index) { $name = mysql_result($sql, $index, "name"); //$address = mysql_result($quer, $index, "address"); $phone = mysql_result($sql, $index, "phone"); $hours = mysql_result($sql, $index, "hours"); $menu = mysql_result($sql, $index, "menu"); $type = mysql_result($sql, $index, "type"); $addr1 = mysql_result($sql, $index, "addr1"); $addr2 = mysql_result($sql, $index, "addr2"); $id = mysql_result($sql, $index, "id"); ?> <table width="503" align="center" class="result"> <tr> <hr color="C9D7F1"> <td width="61" valign="middle"><img src="restpic.gif" alt="" /></td> <td width="122"><p class="th3"><em class="result_name"><?php echo $name; ?></em><br /> <?php echo "$addr1, $addr2"; ?><br /> <a href="javascript:popUp_large('directions.php?daddr=<?php echo "$addr1, $addr2"; ?>');">Directions</a></p></td> <td width="114"><p class="th3"><strong>Hours of Operation:<br /> </strong><?php echo $hours; ?></p></td> <td width="137"><p class="th3"> <a href="listing.php?id=<?php echo $id; ?>#description">Description</a><br /> <?php if($menu == "no") { // DO NOTHING } else { ?> <a href="<?php echo $menu; ?>" target="_blank">Menu</a> <br/> <?php } ?><a href="javascript:alert("For Reservations please call 1-800-566-3921");">Reservations</a><br /> <a href="preparepromo.php?promoname=<?php echo $id; ?>" target="_blank">Promotions</a></p></td> </tr> </table> <?php $index++; } if ($pageno == 1) { echo " FIRST PREV "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; } // if echo " ( Page $pageno of $lastpage ) "; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } // if //End Pagination The error i get is: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/public_html/search.php on line 111 Fatal error: SQL in /home/public_html/search.php on line 111 Line 111: $result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR); any help is appreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/ Share on other sites More sharing options...
ds111 Posted March 30, 2008 Author Share Posted March 30, 2008 ok so i took out the ",$db" in the query so now it is $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); and that error went away. so now here's the error: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/public_html/search.php on line 128 Line 128 is: $num = mysql_numrows($query); here's the block of code: $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT * FROM restaurants WHERE type='$type' $limit"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); $num = mysql_numrows($query); //This is line 128! $index = 0; Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505000 Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 $num = mysql_numrows($result); Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505001 Share on other sites More sharing options...
paul2463 Posted March 30, 2008 Share Posted March 30, 2008 you check for num_rows() from a result resource not a query Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505003 Share on other sites More sharing options...
ds111 Posted March 30, 2008 Author Share Posted March 30, 2008 ok i did that, now there are no errors....BUT...none of the results show up. now what? Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505006 Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 i suggest that you consider an alternative record looping mechanism, for instance: $query = "SELECT * FROM restaurants WHERE type='$type' $limit"; $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); while ($a_row = mysql_fetch_array($result)) { $name = $a_row['name']; $address = $a_row['address']; // etc. etc. etc. } Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505021 Share on other sites More sharing options...
ds111 Posted March 30, 2008 Author Share Posted March 30, 2008 i did that, still no results edit: NVM! I got it to work now!! THANK YOU SO MUCH YOUR DA BOSS!!!!! hey, do u guys have a donate page or something? Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505023 Share on other sites More sharing options...
ds111 Posted March 30, 2008 Author Share Posted March 30, 2008 dammit!!!! when i press next it gives me the "No results" page and im positively sure that there are next results!! Whats going on now??? im really getting ticked off at PHP Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505034 Share on other sites More sharing options...
ds111 Posted March 30, 2008 Author Share Posted March 30, 2008 plz? anyone? help?! Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505071 Share on other sites More sharing options...
ds111 Posted March 30, 2008 Author Share Posted March 30, 2008 please guys...anyone can please help? Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505170 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 lol ok give us your revised code and echo out the mysql query for each page. Ill send u my email via PM, might be able to help you out easier that way. Quote Link to comment https://forums.phpfreaks.com/topic/98675-what-am-i-doing-wrong/#findComment-505467 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.