Gruzin Posted November 27, 2006 Share Posted November 27, 2006 Hi guys,I'am having a trouble with pagination. I have a search script, which works ok and now I want to add some pagination to it... so here is my error:[code]Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /users/3d_cn~1/html/se/search.php on line 86[/code]Thanks for your time,And here is the interesting part of the code:[code]<?phprequire("config.php");if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Define the number of results per page $max_results = 1; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); $query = "SELECT * FROM `Mater` WHERE `MatName` LIKE '%$trimmed%' UNIONSELECT * FROM `Mater` WHERE `MatNameE` LIKE '%$trimmed%'UNIONSELECT * FROM `Mater` WHERE `MatNameR` LIKE '%$trimmed%' ORDER BY `MatName` ASC LIMIT $from,$max_results"; $result = mysql_query($query) or die(mysql_error());$num = mysql_num_rows($result); //number of matching rowsecho "<span class='header'>$num $echo</span>"; // show the number of matching results before loopecho "<br>";echo "<a href='javascript:history.back()'> $back </a>";if($num > 0){ //at least one matchwhile($row = mysql_fetch_assoc($result)){ //to loop through all of the matches//--- start the result echo if($lang == "Georgian"){$res = $row['MatName'];}elseif($lang == "Russian"){$res = $row['MatNameR'];}else{$res = $row['MatNameE'];}echo "<p>";echo $res; echo "<p>";//------- end results} } else{ echo '<p>'; echo "<a href='javascript:history.back()'> $back </a>"; } $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM MatName"),0);// Figure out the total number of pages$total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks echo "<center>Select a Page <br />"; // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i"; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>"; } echo "</center>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/28660-pagination-problem/ Share on other sites More sharing options...
Gruzin Posted November 27, 2006 Author Share Posted November 27, 2006 *Bump* Link to comment https://forums.phpfreaks.com/topic/28660-pagination-problem/#findComment-131168 Share on other sites More sharing options...
Gruzin Posted November 27, 2006 Author Share Posted November 27, 2006 Just don't know how to figure out the max results from db :( Hope someone will help...Thanks anyway,George Link to comment https://forums.phpfreaks.com/topic/28660-pagination-problem/#findComment-131184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.