balamberas Posted January 10, 2010 Share Posted January 10, 2010 Hi, I have a paginations script to display data from my database but i would like to paginate someones search results. I have this script but get an error that says "syntax error, unexpected '=', expecting '}'" for this if(!$start){$start = 0;} <?php include ("connect.php"); $per_page = 20; $start = $_GET ['start']; $record_count = mysql_num_rows (mysql_query("SELECT * FROM flats WHERE `location` LIKE '%$keyword%' OR `location` LIKE '%$keyword%')); $max_pages = $record_count / $per_page; // may come out as a decimal if(!$start){$start = 0;} $get = mysql_query("SELECT * FROM flats WHERE `location` LIKE '%$keyword%' OR `location` LIKE '%$keyword%' ORDER BY date_posted DESC LIMIT $start, $per_page"); ?> Link to comment https://forums.phpfreaks.com/topic/187939-paginate-search-result/ Share on other sites More sharing options...
sasa Posted January 10, 2010 Share Posted January 10, 2010 add " to the end of your SQL command ... `location` LIKE '%$keyword%'")); Link to comment https://forums.phpfreaks.com/topic/187939-paginate-search-result/#findComment-992288 Share on other sites More sharing options...
balamberas Posted January 10, 2010 Author Share Posted January 10, 2010 thanks, I have one more problem. the prev 1 2 3 4 next is not giving the result i want. I get the error msg: Notice: Undefined index: submit, Notice: Undefined index: search you didnt submit a keyword. I know that when i press 2 it read search.php again but I dont know how to solve it. <header> <?php include ("connect.php"); $per_page = 20; $start = $_GET ['start']; $record_count = mysql_num_rows (mysql_query("SELECT * FROM flats WHERE `location` LIKE '%$keyword%' OR `location` LIKE '%$keyword%'")); $max_pages = $record_count / $per_page; // may come out as a decimal if(!$start){$start =0;} $get = mysql_query("SELECT * FROM flats WHERE `location` LIKE '%$keyword%' OR `location` LIKE '%$keyword%' ORDER BY date_posted DESC LIMIT $start, $per_page"); ?> </header> <body> <td> <tr> <?php include ('connect.php'); error_reporting(E_ALL); ini_set('display_errors', '1'); $submit = $_GET['submit']; $search = $_GET['search']; $x=0; $construct=''; $foundnum=0; if (!$submit) echo "you didnt submit a keyword."; else { if (strlen($search)<=2) echo "search term to short."; else { echo " You searched for <b>$search</b><hr size='1'>"; //connect to our database $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { // construct query $x++; if ($x==1) $construct .= " location LIKE '%$search_each%'"; else $construct .= " OR location LIKE '%$search_each%'"; } // echo out construct $construct = "SELECT * FROM flats WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "No results found."; else { echo "$foundnum result found!<p>"; while ($runrows = mysql_fetch_assoc($run)) { // get data $select = $runrows['type']; $title = $runrows['title']; $location = $runrows['location']; $rent = $runrows['rent']; $description = $runrows['description']; $contactEmail = $runrows['contactEmail']; $number = $runrows['number']; echo " $title <br> $select <br> $rent <br> $location <br> $description <br> $contactEmail <br> $number <hr>"; } } } } ?> </td> </tr> <tr align="center"> <td> <?php $prev = $start - $per_page; $next = $start + $per_page; if($start>0){ echo "<a href='search.php?start=$prev'> Prev </a>";} $i=1; for ($x=0;$x<$record_count;$x=$x+$per_page) { if($start!=$x){ echo "<a href='search.php?start=$x'>$i | </a>"; } else{ echo "<a href='search.php?start=$x'><b> $i | </b></a>";} $i++; } if($start<$record_count-$per_page){echo "<a href='search.php?start=$next'> Next </a>";} ?> Link to comment https://forums.phpfreaks.com/topic/187939-paginate-search-result/#findComment-992409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.