sandbudd Posted August 9, 2009 Share Posted August 9, 2009 Hi guys simple search engine code but when there are more than 10 results it displays the total number of results and displays the first ten but will not click through to the next ten? <?php $var = @$_GET['q'] ; $trimmed = trim($var); $limit=10; if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } mysql_connect("","",""); //(host, username, password) mysql_select_db("") or die("Unable to select database"); $query = "select * from employees where company like \"%$trimmed%\" order by company"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); echo "<p>You searched for: "" . $var . ""</p>"; $count = 1 + $s ; while ($row= mysql_fetch_array($result)) { $title = $row["company"]; echo "$count.) $title <br>" ; $count++ ; } $currPage = (($s/$limit) + 1); echo "<br />"; if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } $pages=intval($numrows/$limit); if ($numrows%$limit) { $pages++; } if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169491-simple-search-does-not-display-next/ Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 this is called pagination, however after skimming your code your not using $_GET['s'] ie $s = $_GET['s'] Quote Link to comment https://forums.phpfreaks.com/topic/169491-simple-search-does-not-display-next/#findComment-894252 Share on other sites More sharing options...
sandbudd Posted August 9, 2009 Author Share Posted August 9, 2009 MadTeckie that did it thanks $count = 1 + $s = $_GET['s'] ; Quote Link to comment https://forums.phpfreaks.com/topic/169491-simple-search-does-not-display-next/#findComment-894259 Share on other sites More sharing options...
sandbudd Posted August 9, 2009 Author Share Posted August 9, 2009 sorry guys though it was solved but now the count is off it says displaying something like 11 to 13 of 13 when there are 20 results...that is just an example? Quote Link to comment https://forums.phpfreaks.com/topic/169491-simple-search-does-not-display-next/#findComment-894273 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.