Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function makepagenav($start, $count, $total, $range = 0, $link = "") {
  2.  
  3. global $locale;
  4.  
  5. if ($link == "") {
  6. $link = $_SERVER['PHP_SELF']."?";
  7. }
  8.  
  9. $pg_cnt = ceil($total / $count);
  10. if ($pg_cnt <= 1) {
  11. return "";
  12. }
  13.  
  14. $idx_back = $start - $count;
  15. $idx_next = $start + $count;
  16. $cur_page = ceil(($start + 1) / $count);
  17.  
  18. echo "<div id= 'stranky'>";
  19. $res = "Stránka ".$cur_page." z ".$pg_cnt.": ";
  20. echo "</div>";
  21. if($idx_back >= 0) {
  22. if($cur_page > ($range + 1)) {
  23. $res .= "<a href='".$link."rowstart=0'>1</a>...";
  24. }
  25. }
  26. $idx_fst = max($cur_page - $range, 1);
  27. $idx_lst = min($cur_page + $range, $pg_cnt);
  28. if ($range == 0) {
  29. $idx_fst = 1;
  30. $idx_lst = $pg_cnt;
  31. }
  32. for ($i = $idx_fst; $i <= $idx_lst; $i++) {
  33. $offset_page = ($i - 1) * $count;
  34. if ($i == $cur_page) {
  35. $res .= "<span><strong>".$i."</strong></span>";
  36. } else {
  37. $res .= "<a href='".$link."rowstart=".$offset_page."'>".$i."</a>";
  38. }
  39. }
  40. if ($idx_next < $total) {
  41. if ($cur_page < ($pg_cnt - $range)) {
  42. $res .= "...<a href='".$link."rowstart=".($pg_cnt - 1) * $count."'>".$pg_cnt."</a>\n";
  43. }
  44. }
  45.  
  46. return "<div class='pagenav'>\n".$res."</div>\n";
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement