Advertisement
niammuddin

pagination sphinx search

Oct 3rd, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php
  2. // Start Pagination
  3.  
  4. // number of rows to show per page
  5. $rowsperpage = 10;
  6. $numrows1 = $results[total];
  7.  
  8. // find out total pages
  9. $totalpages = ceil($numrows1 / $rowsperpage);
  10.  
  11. // get the current page or set a default
  12. if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
  13.       // cast var as int
  14.       $currentpage = (int) $_GET['currentpage'];
  15.       } else {
  16.       // default page num
  17.       $currentpage = 1;
  18. } // end if
  19.  
  20. // if current page is greater than total pages...
  21. if ($currentpage > $totalpages) {
  22.       // set current page to last page
  23.       $currentpage = $totalpages;
  24. } // end if
  25.  
  26. // if current page is less than first page...
  27. if ($currentpage < 1) {
  28.       // set current page to first page
  29.       $currentpage = 1;
  30. } // end if
  31.  
  32. // the offset of the list, based on current page
  33. $offset = (($currentpage - 1) * $rowsperpage);
  34.  
  35. $sphinx->SetLimits($offset, $rowsperpage);
  36.  
  37. echo "<b>Found $results[total_found] Matches</b><br>\n";
  38.  
  39. $showingto = ($offset + $rowsperpage > $numrows1) ? $numrows1 : $offset + $rowsperpage;
  40. echo "Showing results " . ($offset+1) . " - " . $showingto . " of " . $numrows1;
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement