simmsy Posted March 18, 2010 Share Posted March 18, 2010 Hi ive almost got my website up and running im just having trouble with the pagination on the search engine. It shows the first 4 (or how ever many I have set) results then when I click next page it just displays the error of the search engine bar and not the rest of the search, please help, im desperate?? Heres the code: <?php include("connect.php"); //max displayed per page $per_page = 4; //get start variable $start = $_GET['start']; //count records $record_count = mysql_num_rows(mysql_query("SELECT * FROM search")); //count max pages $max_pages = $record_count / $per_page; //may come out as decimal if (!$start) $start = 0; //get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button){ echo "<span class='class2 style39'>You didn't submit a keyword.</span>"; }else{ if (strlen($search)<=2){ echo "Search term too short."; }else{ echo "You searched for <b>$search</b><hr size='1'>"; //connect to our datebase include("connect.php"); //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%'"; } } $construct = "SELECT * FROM search WHERE $construct LIMIT $start, $per_page"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum == 0){ echo "No results found."; }else{ echo "$foundnum results found!"; while ($runrows = mysql_fetch_assoc($run)){ //get data $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; $picture = $runrows['picture']; echo "<br/><br/><table width='600' align='center'> <tr> <td width='74' rowspan='3' align='left' valign='middle'><a href='$url'><img src='$picture' height='100' width='100' border='0'></a></td> <td align='center' valign='middle'><b>$title</b></td> </tr> <tr> <td align='center' valign='middle'>$desc</td> </tr> <tr> <td align='center' valign='middle'><a href='$url'>$url</a></td> </tr> </table><p></p>"; } //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='pagination.php?start=$prev'>Prev</a> "; //show page numbers //set variable for first page $i=1; for ($x=0;$x<$record_count;$x=$x+$per_page) { if ($start!=$x) echo " <href='pagination.php?start=$x'>$i</a> "; else echo " <a href='pagination.php?start=$x'><b>$i</b> "; $i++; } //show next button if (!($start>=$record_count-$per_page)) echo " <a href='pagination.php?start=$next'>Next</a>"; } } } ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/195739-search-with-pagination-help-please/ Share on other sites More sharing options...
Hybride Posted March 19, 2010 Share Posted March 19, 2010 Please use the php/code tags next time. I briefly glanced over, and this stuck out: for ($x=0;$x<$record_count;$x=$x+$per_page) { if ($start!=$x) echo " <href='pagination.php?start=$x'>$i</a> "; else echo " <a href='pagination.php?start=$x'><b>$i</b> "; $i++; } The first line was missing an "a" echo " <a href='pagination.php?start=$x'>$i</a> "; and the second was missing a closing tag echo " <a href='pagination.php?start=$x'><b>$i</b> </a> "; Quote Link to comment https://forums.phpfreaks.com/topic/195739-search-with-pagination-help-please/#findComment-1028380 Share on other sites More sharing options...
simmsy Posted March 19, 2010 Author Share Posted March 19, 2010 good spoting but still didnt solve the problem still goes back to the search page and says 'you didnt enter a search word' with no search bar Quote Link to comment https://forums.phpfreaks.com/topic/195739-search-with-pagination-help-please/#findComment-1028477 Share on other sites More sharing options...
isedeasy Posted March 19, 2010 Share Posted March 19, 2010 Are you including the search term in the page links? if ($start!=$x) echo " <a href=\"pagination.php?search=$search&start=$x\">$i</a> "; else echo " <a href=\"pagination.php?search=$search&start=$x\"><b>$i</b></a> "; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/195739-search-with-pagination-help-please/#findComment-1028537 Share on other sites More sharing options...
simmsy Posted March 19, 2010 Author Share Posted March 19, 2010 ive added those and still the same thing happens its frustrating Quote Link to comment https://forums.phpfreaks.com/topic/195739-search-with-pagination-help-please/#findComment-1028793 Share on other sites More sharing options...
simmsy Posted March 19, 2010 Author Share Posted March 19, 2010 I get the first page with the first set of results and click next page and says 'you didnt submit a search word' and the results say theres only 4 (or how many i set it too)? Quote Link to comment https://forums.phpfreaks.com/topic/195739-search-with-pagination-help-please/#findComment-1028798 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.