Posted By

andyhartleeds on 11/23/07


Tagged

results next previous limiting resultset


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

luman


Next and Previous links/limiting results


 / Published in: PHP
 

  1. $sort_by = ($_GET["sort_by"]) ? $_GET["sort_by"] : "created";
  2. $sort_order = ($_GET["sort_order"]) ? $_GET["sort_order"] : "DESC";
  3. $opposite_sort_order = ($sort_order == "ASC") ? "DESC" : "ASC";
  4. $start = ($_GET["start"]) ? $_GET["start"] : 0;
  5. $results_limit = 10;
  6.  
  7. ...
  8.  
  9. $total_results = mysql_num_rows($result);
  10. $query .= "ORDER BY " . $sort_by . " " . $sort_order . " LIMIT " . $start . ", " . $results_limit . ";";
  11.  
  12. ...
  13.  
  14. if ($start > 0) {
  15. ?>
  16. <p style="float: left;"><a href="?sort_by=<?=$sort_by?>&sort_order=<?=$sort_order?>&start=<?=$start - $results_limit?>">&lt; Previous</a></p>
  17. <?php
  18. }
  19. if (($start + $results_limit) < $total_results) {
  20. ?>
  21. <p style="float: right;"><a href="?sort_by=<?=$sort_by?>&sort_order=<?=$sort_order?>&start=<?=$start + $results_limit?>">Next &gt;</a></p>
  22. <?php
  23. }

Report this snippet  

You need to login to post a comment.