jetzzz Posted May 24, 2010 Share Posted May 24, 2010 Hi PHP Gurus. I've been looking for a script with search pagination in it. To my avail, i cant find any. Can you guys help me with my code? I can successfully output the search result in the table but i can't figure out how to make Previous and Next links work. Hope you can help me out. Below is my code. <?php //max displayed per page $per_page = 5; //get start variable //$var = @$_GET['q'] ; $start = $_GET['start']; $s = $_GET['s'] ; $search = @$_GET['Search']; $search_type = $_GET['SearchType']; $Submitted = $_GET['Submitted']; $result = mysql_query("SELECT * FROM tblbrr ORDER by fldID"); //num or die("SELECT Error: ".mysql_error()); $record_count = mysql_num_rows($result); //count max per page $max_pages = $record_count/$per_page; if(!$start) $start = 0; if (!(empty($_GET['Search']))) { $get = mysql_query("SELECT * FROM tblbrr where $search_type like \"%$search%\" LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($get)) { $RefNo = $row["fldReferenceNo"]; $ProjectName = $row["fldProcess"]; $Description = $row["fldDescription"]; $AssignedTo= $row["fldAssignedTo"]; $Status= $row["fldStatus"]; echo "<TR>\n" ."<TD">"."<a href=\"brr_view.php?link=$RefNo&ID=$id&Source=search&Status2=$Status\">$RefNo</a>"."</TD> \n" ."<TD">".$ProjectName."</TD>\n" ."<TD">".$Description."</TD>\n" ."<TD">".$AssignedTo."</TD>\n" ."<TD">".$Status."</TD>\n" ."</TR>"; } $result_open= mysql_query("SELECT * FROM tblbrr where $search_type like \"%$search%\""); $ctr_open = mysql_num_rows($result_open); echo 'Search results ', $ctr_open; //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; } ?> </table> <?php if ($Submitted == 1){ //show prev button if (!($start <= 0 )) echo "<a href='$PHP_SELF?start=$prev?search=$search?searchtype=$search_type'>Prev</a> "; //set variable for first page //$i = 1; //show page numbers //for ($x=0; $x < $record_count; $x=$x+$per_page) //{ //if ($start != $x) //echo "<a href='tabletype_brr_search.php?start=$x'>$i</a> "; //else //echo "<a href='tabletype_brr_search.php?start=$x'>$i</a> "; //$i++; //} //show next button if (!($start >= $record_count-$per_page)) echo "<a href='$PHP_SELF?start=$next?search=$result_open'>Next</a> "; } ?> Link to comment https://forums.phpfreaks.com/topic/202697-need-help-search-with-pagination/ Share on other sites More sharing options...
-Karl- Posted May 24, 2010 Share Posted May 24, 2010 Please use PHP tags >.> Link to comment https://forums.phpfreaks.com/topic/202697-need-help-search-with-pagination/#findComment-1062449 Share on other sites More sharing options...
jetzzz Posted May 24, 2010 Author Share Posted May 24, 2010 Oops im sorry. here it is. <?php //max displayed per page $per_page = 5; //get start variable //$var = @$_GET['q'] ; $start = $_GET['start']; $s = $_GET['s'] ; $search = @$_GET['Search']; $search_type = $_GET['SearchType']; $Submitted = $_GET['Submitted']; $result = mysql_query("SELECT * FROM tblbrr ORDER by fldID"); //num or die("SELECT Error: ".mysql_error()); $record_count = mysql_num_rows($result); //count max per page $max_pages = $record_count/$per_page; if(!$start) $start = 0; if (!(empty($_GET['Search']))) { $get = mysql_query("SELECT * FROM tblbrr where $search_type like \"%$search%\" LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($get)) { $RefNo = $row["fldReferenceNo"]; $ProjectName = $row["fldProcess"]; $Description = $row["fldDescription"]; $AssignedTo= $row["fldAssignedTo"]; $Status= $row["fldStatus"]; echo "<TR>\n" ."<TD">"."<a href=\"brr_view.php?link=$RefNo&ID=$id&Source=search&Status2=$Status\">$RefNo</a>"."</TD> \n" ."<TD">".$ProjectName."</TD>\n" ."<TD">".$Description."</TD>\n" ."<TD">".$AssignedTo."</TD>\n" ."<TD">".$Status."</TD>\n" ."</TR>"; } $result_open= mysql_query("SELECT * FROM tblbrr where $search_type like \"%$search%\""); $ctr_open = mysql_num_rows($result_open); echo 'Search results ', $ctr_open; //setup prev and next variables $prev = $start - $per_page; $next = $start + $per_page; } ?> </table> <?php if ($Submitted == 1){ //show prev button if (!($start <= 0 )) echo "<a href='$PHP_SELF?start=$prev?search=$search?searchtype=$search_type'>Prev</a> "; //set variable for first page //$i = 1; //show page numbers //for ($x=0; $x < $record_count; $x=$x+$per_page) //{ //if ($start != $x) //echo "<a href='tabletype_brr_search.php?start=$x'>$i</a> "; //else //echo "<a href='tabletype_brr_search.php?start=$x'>$i</a> "; //$i++; //} //show next button if (!($start >= $record_count-$per_page)) echo "<a href='$PHP_SELF?start=$next?search=$result_open'>Next</a> "; } ?> Link to comment https://forums.phpfreaks.com/topic/202697-need-help-search-with-pagination/#findComment-1062453 Share on other sites More sharing options...
phpmady Posted May 24, 2010 Share Posted May 24, 2010 Hi, Go through this, you wll get a good idea, its good for beginner http://www.phpeasystep.com/phptu/29.html thanks Link to comment https://forums.phpfreaks.com/topic/202697-need-help-search-with-pagination/#findComment-1062585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.