john-formby Posted June 30, 2006 Share Posted June 30, 2006 Hi,I have a search on my website which is working perfectly thanks to the help I have received on this site :) The only problem is that some seaches could return hundreds of results so I would really like a way of splitting them up into pages. I deally I would like something like [1] [2] [3] with the current page number not clickable. I don't know how to do this though. I have tried adapting some stuff I found online but I can't get any of it to work ???Here is my search processing and results page:[code]<? //This is only displayed if they have submitted the form if ($_POST['searching'] =="yes") { //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "USER", "PASS") or die(mysql_error()); mysql_select_db("pagelinks") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM links WHERE keywords LIKE '%$find%'"); //And we display the results while($result = mysql_fetch_array( $data )) { echo "<hr /><br />";if ($result['new_window'] == 1) { echo "<b><a href=\"".$result['url']."\" target=\"_new\">".$result['link_text']."</a></b>"; } else { echo "<b><a href=\"".$result['url']."\">".$result['link_text']."</a></b>"; } echo "<br />"; echo $result['description']; echo "<br />"; if ($result['new_window'] == 1) { echo "<a href=\"".$result['url']."\" target=\"_new\">".$result['url']."</a>"; } else { echo "<a href=\"".$result['url']."\">".$result['url']."</a>"; }echo "<br /><br />"; } echo "<hr /><br />";//This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?>[/code]Thanks,John Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/ Share on other sites More sharing options...
Orio Posted June 30, 2006 Share Posted June 30, 2006 Lots of them out there:http://www.google.com/search?hl=en&lr=&q=php+paging+scriptOrio. Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/#findComment-51153 Share on other sites More sharing options...
john-formby Posted June 30, 2006 Author Share Posted June 30, 2006 I have had a few attempts and can now get the page numbers to display the way I want them. Unfortunately I no longer have any results displayed and I get the message error message "Sorry, but we can not find an entry to match your query"Please can someone look at the code below and tell me where I have gone wrong. [code]<? //This is only displayed if they have submitted the form if ($searching =="yes") { //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "USER", "PASS") or die(mysql_error()); mysql_select_db("pagelinks") or die(mysql_error()); $pageSize = 5;$pageNumber = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;// We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $query="SELECT * FROM links WHERE keywords LIKE '%$find%'".(($page-1) * $pageSize).','.$pageSize; $result=mysql_query($query);//And we display the results while ($row = mysql_fetch_assoc($result)) { echo "<hr /><br />";if ($result['new_window'] == 1) { echo "<b><a href=\"".$result['url']."\" target=\"_new\">".$result['link_text']."</a></b>"; } else { echo "<b><a href=\"".$result['url']."\">".$result['link_text']."</a></b>"; } echo "<br />"; echo $result['description']; echo "<br />"; if ($result['new_window'] == 1) { echo "<a href=\"".$result['url']."\" target=\"_new\">".$result['url']."</a>"; } else { echo "<a href=\"".$result['url']."\">".$result['url']."</a>"; }echo "<br /><br />"; } echo "<hr /><br />";//This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($result); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find. "<br/><br />"; }$numberOfRecords = mysql_result(mysql_query("SELECT count(*) FROM links WHERE keywords LIKE '%$find%'"),0,0);for($i = 0; $i < $numberOfRecords; $i += $pageSize) { $page = 1 + ceil($i/$pageSize); echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$page.'"> [ '.$page.' ] </a>';} ?>[/code]Thanks,John Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/#findComment-51288 Share on other sites More sharing options...
nogray Posted June 30, 2006 Share Posted June 30, 2006 You are forgeting the limit in the query[code]keywords LIKE '%$find%' limit ".(($page-1) * $pageSize).','.$pageSize[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/#findComment-51313 Share on other sites More sharing options...
john-formby Posted June 30, 2006 Author Share Posted June 30, 2006 Thanks, but the results are still not showing up ???John Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/#findComment-51319 Share on other sites More sharing options...
nogray Posted June 30, 2006 Share Posted June 30, 2006 try to add mysq_error() to your query to find out if you have any errors[code]$result=mysql_query($query) or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/#findComment-51383 Share on other sites More sharing options...
john-formby Posted June 30, 2006 Author Share Posted June 30, 2006 Yay, its sorted ;D Pages needed to be set up as an array.John Quote Link to comment https://forums.phpfreaks.com/topic/13285-search-results-pagination/#findComment-51460 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.