MDanz Posted August 15, 2009 Share Posted August 15, 2009 this is the working search engine, underneath is the pagination i have implemented. $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "<br>You didn't submit a keyword"; else { if(!isset($search) || strlen($search)<=2) echo "<br><font color=white><br>search term too short</font>"; else { echo "<br><br><font color=white><br>you searched for <b>$search</b></font><hr size='1'>"; } mysql_connect("localhost", "Master", "password"); mysql_select_db("Ustack"); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if($x==1) $construct .= "keywords LIKE '%$search_each%'"; else $construct .= "OR keywords LIKE '%$search_each%'"; } //echo out $construct $construct = "SELECT * FROM Stacks WHERE $construct"; } $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "<br><br><font color=white>No Stacks Found</font>"; else { echo "<font color=white>$foundnum <img src='http://www.u-stack.com/mini%20stack.jpg'> Found!</font><hr size='1'><p>"; if($_GET['RadioGroup1']== 1 ) $margin = 'style="margin-left:60px"'; else if($_GET['RadioGroup1']== 2 ) $margin = 'style="margin-left:120px"'; else if($_GET['RadioGroup1']== 3 ) $margin = 'style="margin-left:180px"'; else if($_GET['RadioGroup1']== 4 ) $margin = 'style="margin-left:240px"'; else if($_GET['RadioGroup1']== 5 ) $margin = 'style="margin-left:300px"'; else if($_GET['RadioGroup1']== 6 ) $margin = 'style="margin-left:360px"'; else if($_GET['RadioGroup1']== 7 ) $margin = 'style="margin-left:420px"'; else if($_GET['RadioGroup1']== 8 ) $margin = 'style="margin-left:480px"'; else $margin = 'style="margin-left:0px"'; echo '<table '.$margin.'>'; while ($runrows = mysql_fetch_assoc($run)) { //get data $id = $runrows['id']; $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; $rating = $runrows['rating']; echo '<td><tr>'; switch ($type) { case 'I': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'M': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'F': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'V': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'J': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'D': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; case 'P': echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; break; } echo "</tr><font color=white><strong> $name - $info - $rating <a href='rate.php?id=$id'><img src='http://www.u-stack.com/rate.jpg'></a></center><br><br><hr size='1'></strong></font></td>"; } echo '</table>'; } Now this is the pagination i have implemented. It is recognizing the results and displays the appropriate pages but doesn't put the results on those pages, they are only on page 1. On page 2 it says Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ustackc1/public_html/search.php on line 102 // number of rows to show per page $runrowsperpage = 5; // find out total pages $totalpages = ceil($foundnum / $runrowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if $offset = ($currentpage - 1) * $runrowsperpage; $runrowsrange = 3; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // loop to show links to range of pages around current page for ($x = ($currentpage - $runrowsrange); $x < (($currentpage + $runrowsrange) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ Any help much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/170360-warning-mysql_num_rows/ Share on other sites More sharing options...
sKunKbad Posted August 15, 2009 Share Posted August 15, 2009 What it is telling you is that your query isnt returning any results. Try: if(mysql_num_rows($run) > 0) { // there was at least one row returned by the query... do something with it } else { // there was no results } Quote Link to comment https://forums.phpfreaks.com/topic/170360-warning-mysql_num_rows/#findComment-898720 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.