bickyz Posted April 6, 2013 Share Posted April 6, 2013 hi, I have following php search code (grateful to another forum member Barand for his help) that pulls the data from mysql, I would like only 6 results to be displayed on first page then rest to be paginated. I am trying to follow these tutorials from phpfreaks.com/tutorial/basic-pagination & jadendreamer.wordpress.com/2012/11/20/php-tutorial-searching-and-pagination but I have no clue how to integrate the pagination code; Could someone please assist me. Here is the search page demo Your help will be much appreciated, thank you. <?php if(isset($_REQUEST['searchbtn'])){ $where = array(); $whereclause = ''; if (!empty($_POST['duration'])) { $val = intval($_POST['duration']); $where[] = "(acdur = $val)"; } if (!empty($_POST['transport'])) { $val = mysql_real_escape_string($_POST['transport']); $where[] = "(actransp = '$val')"; } if (!empty($_POST['datepicker'])) { $val = mysql_real_escape_string($_POST['datepicker']); $where[] = "(acdate = '$val')"; } if (isset($_POST['activity'])) { $val = join(",", array_map('intval', $_POST['activity'])); $where[] = "(incl_activity.incid IN ($val))"; } if (count($where)) $whereclause = "WHERE " . join(' AND ', $where); $query = "SELECT activities.*, teamleader.tlname, GROUP_CONCAT(incdesc SEPARATOR ', ') as Includes FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid $whereclause GROUP BY activities.acid ORDER BY activities.accost ASC"; $test= mysql_query($query) or die(mysql_error()); if(mysql_num_rows($test)) { $i=0; while($row = mysql_fetch_assoc($test)){ $actitle=$row["actitle"]; $tlname=$row["tlname"]; $acdate=$row["acdate"]; $acdur=$row["acdur"]; $accost=$row["accost"]; $incdesc=$row["Includes"]; $actransp=$row["actransp"]; echo "<div style='width:250px; padding:10px; float:left;'> $actitle <br> $tlname <br> $acdate <br> $acdur <br> $accost <br> $incdesc <br> $actransp </div>"; $i++; if($i % 3 == 0) echo "<div style='clear:both'></div>\n"; } if ($i%3) echo "<div style='clear:both'></div>\n"; } else { echo '<div align=center style="margin:20px; font-family:Arial, Helvetica, sans-serif; font-size: 20px; font-weight:bold; color: #ae1919;">Your search did not match any results.</div>'; header('Refresh: 5; URL=search.php'); } } ?> </body> </html> <?php mysql_free_result($test); ?> Link to comment https://forums.phpfreaks.com/topic/276622-how-to-add-pagination-for-the-search-results/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.