PHP Pagination


SUBMITTED BY: Guest

DATE: July 9, 2013, 8:34 a.m.

FORMAT: PHP

SIZE: 2.1 kB

HITS: 1052

  1. <?php
  2. class html_parser {
  3. public function html_parser() {
  4. }
  5. public static function make_pageination($entry_count, $onclick, $current_page = 1, $entries_per_page = 10) {
  6. $max_pages = ceil($entry_count / $entries_per_page);
  7. if($max_pages == 1) return array("content" => '', "mysql" => "");
  8. $ret_entry = '<div class="pagination">';
  9. if($current_page <= 5) $startpage = 1;
  10. else {
  11. $startpage = (int)$current_page-3;
  12. $js_string = str_replace("###page###","1", $onclick);
  13. $link_to_one = '<span class="nav_entry" onClick="' . $js_string . '">1</span>
  14. <span class="nav_points">...</span>';
  15. }
  16. if($current_page > 1) {
  17. $js_string = str_replace("###page###",$current_page-1, $onclick);
  18. $backlink = '<span class="nav_entry" onClick="' . $js_string . '">Zurück</span>';
  19. }
  20. if(($max_pages - 3) <= $current_page) $end_page = $max_pages;
  21. else {
  22. $end_page = $current_page + 3;
  23. $js_string = str_replace("###page###",$max_pages, $onclick);
  24. $link_to_last = '<span class="nav_points">...</span><span class="nav_entry" onClick="' . $js_string . '">' . $max_pages . '</span>';
  25. }
  26. if($current_page < $max_pages) {
  27. $js_string = str_replace("###page###",$current_page+1, $onclick);
  28. $forwardlink = '<span class="nav_entry" onClick="' . $js_string . '">Weiter</span>';
  29. }
  30. $ret_entry .= $backlink . $link_to_one;
  31. for($i = $startpage; $i<=$end_page;$i++) {
  32. $js_string = str_replace("###page###",($i), $onclick);
  33. $ret_entry .= '<span onclick="' . $js_string . '"';
  34. if($i == $current_page) {
  35. $ret_entry .= ' class="nav_entry_current"';
  36. }
  37. else {
  38. $ret_entry .= ' class="nav_entry"';
  39. }
  40. $ret_entry .= '>'.($i) .'</span>';
  41. }
  42. $ret_entry .= $link_to_last . $forwardlink;
  43. $ret_entry .= '</div>';
  44. return $ret_entry;
  45. }

comments powered by Disqus