Clinton Posted January 3, 2009 Share Posted January 3, 2009 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 98 and 108 <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($sql); ///HERE/// $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted '$max'"; if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p)) ///AND HERE/// { extract($row); ?> I'm trying to paginate and then echo an else if there are no rows (hence the two statements. Not sure how to fix this. Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/ Share on other sites More sharing options...
Adam Posted January 3, 2009 Share Posted January 3, 2009 Extremely common problem, try searching the forum for: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" .. Try switching: $rs = mysql_query($sql); To: $rs = mysql_query($sql) or die(mysql_error()); A Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-728980 Share on other sites More sharing options...
Clinton Posted January 3, 2009 Author Share Posted January 3, 2009 Yea, I searched. Found nothing that helped. Yea, I put that in before I post but it gave me nothing. It just echoed the same error. No details. Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-728986 Share on other sites More sharing options...
Clinton Posted January 3, 2009 Author Share Posted January 3, 2009 I think I figured out the first error. I changed: $rows = mysql_num_rows($sql); to $rows = mysql_num_rows($rs); But I'm still getting that second one... :-/ Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-728989 Share on other sites More sharing options...
Adam Posted January 3, 2009 Share Posted January 3, 2009 Hah beat me to the first mistake there. And for the second you have't executed the query. Should be: $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted '$max'"); A Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-728990 Share on other sites More sharing options...
Clinton Posted January 3, 2009 Author Share Posted January 3, 2009 Yea, I just got that too. :-) Now I'm not getting those errors anymore but it's not working correctly and it has something to do with that $max variable. "The first thing we do is re-run our query from earlier, only with one slight change. This time we are including the $max variable to limit the query results to those that belong on our current page. After your query you would display your results as normal (using any formatting you wish.)" Their Example - $data_p = mysql_query("SELECT * FROM topsites $max") or die(mysql_error()); :-| Any idea about this? Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-728994 Share on other sites More sharing options...
premiso Posted January 3, 2009 Share Posted January 3, 2009 "SELECT * FROM topsites LIMIT $max" You need the LIMIT keyword in there before $max. Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-729000 Share on other sites More sharing options...
Clinton Posted January 4, 2009 Author Share Posted January 4, 2009 Ok, gotcha. Now it is limiting the search results correctly but it is not displaying the code on the bottom that allows me to go to the next page. Any ideas there? <table width="95%" border="0" cellspacing="0" cellpadding="1" class="boxtitle"> <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($rs); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jobposted $max"); if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p) or die(mysql_error())) { extract($row); ?> <thead> <tr><td> <a href="show.php?id=<?php echo $id ?>"><?php echo $jtitle ?></a> </td></tr> </thead> <tr><td> Blah Blah </td></tr> <?php } ///EVERYTHING BELOW THIS IS NOT SHOWING///?> <? echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) {} else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) {} else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> </table> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-729009 Share on other sites More sharing options...
premiso Posted January 4, 2009 Share Posted January 4, 2009 <?php } ///EVERYTHING BELOW THIS IS NOT SHOWING/// echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) {} else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) {} else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> </table> <?php } ?> Try that. Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-729021 Share on other sites More sharing options...
Clinton Posted January 4, 2009 Author Share Posted January 4, 2009 No, that didn't work either. But I just noticed that my footer isn't showing either so there's got to be something in there that's stopping the code period... ??? <div id="content"> <div class="content-tl"> <div class="content-tr"> <div class="width"> <div id="boxes"> <div id="box1"> <div class="module"> <div class="first"> <div class="sec min-height"> <div class="box-indent"> <div class="width"> <h3><span><?php echo $smajor ?> So:</span></h3> <table width="95%" border="0" cellspacing="0" cellpadding="1" class="boxtitle"> <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($rs); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted $max"); if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p) or die(mysql_error())) { extract($row); ?> <thead> <tr><td> <a href="showad.php?id=<?php echo $id ?>"><?php echo $title ?></a> - <?php echo $sse ?> - Required: <?php echo $wex ?> </td></tr> </thead> <tr><td> <?php echo $poverview ?><br /> </td></tr> <?php } ?> <?php } ///EVERYTHING BELOW THIS IS NOT SHOWING/// echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) {} else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) {} else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } ?> </table> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div id="footer"> <div class="bg"> <div class="right-bg"> <div class="left-bg"> <div class="space"> © 2009 </div> </div> </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-729033 Share on other sites More sharing options...
Clinton Posted January 4, 2009 Author Share Posted January 4, 2009 Whatever the problem is it is here: <?php if (!(isset($pagenum))) { $pagenum = 1; } $sql = "SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted"; $rs = mysql_query($sql); $rows = mysql_num_rows($rs); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last;} $max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; $sql_p = mysql_query("SELECT * FROM thelist WHERE dmajorp = '$smajor' ORDER BY jposted $max"); if(mysql_num_rows($rs) > 0){ while($row = mysql_fetch_array($sql_p) or die(mysql_error())) { extract($row); ?> Because when I take it out everything else (i.e. the footer) shows up just fine. But i'm not getting any errors. w...t...h...??? Quote Link to comment https://forums.phpfreaks.com/topic/139375-solved-num_rows-error-help/#findComment-729132 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.