Advertisement
Guest User

Break page links

a guest
Dec 31st, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. // Paging
  2. $maxPerPage = 10;
  3. $cutStarting = 5;
  4. $prevPageNum = 0;
  5.  
  6. //set currentPageId
  7. $currentPage = isset($_GET['pagenum']) ? intval($_GET['pagenum']) : 1;
  8.  
  9. //set first row (maybee for limits in mysql query)
  10. $firstRow = ($currentPage * $maxPerPage) - ($maxPerPage) + 1;
  11.  
  12. $catglobal_sql = "select SQL_CALC_FOUND_ROWS p.*, case when p.specials_new_products_price > 0.0000 and (p.expires_date > Now() or p.expires_date IS NULL or p.expires_date ='0000-00-00 00:00:00') and p.status != 0 then p.specials_new_products_price else p.products_price end price from ".TABLE_GLOBAL_PRODUCTS." p INNER JOIN ".TABLE_STORES." s ON s.blog_id = p.blog_id " . $join_like_table . " where (p.products_name like '%".$search_key."%' or p.products_description like '%".$search_key."%') and p.display_product = '1' and p.products_status = '1' order by p.products_date_added DESC, p.products_name LIMIT " . $firstRow . ", " . $maxPerPage;
  13.  
  14. $get_products = $wpdb->get_results($catglobal_sql, ARRAY_A);
  15. $count_rows = $wpdb->get_row("SELECT FOUND_ROWS()", ARRAY_A);
  16. $num_count = $count_rows['FOUND_ROWS()'];
  17.  
  18. echo '<div id="results">';
  19. foreach ($get_products as $catglobal_2) {
  20. // Data Results
  21. }
  22. if (!$get_products) {
  23. echo '<p>There are no products matching your criteria.</p>';
  24. }
  25. echo '<div style="clear:both"></div>';
  26. ?>
  27. </div>
  28. <?php
  29. //set params
  30. $total = $num_count;
  31. $totalPages = ceil($total / $maxPerPage);
  32.  
  33. if ($currentPage > $totalPages && $currentPage < 1) {
  34. $currentPage = 1;
  35. }
  36.  
  37. //calculate prev link pageId
  38. if ($currentPage > $cutStarting) {
  39. $prevPageNum = floor(($currentPage - 1) / $cutStarting) * $cutStarting;
  40. echo '[ <a href="?pagenum='.$prevPageNum.'">Prev 5</a> ] ';
  41. }
  42.  
  43. //generate number page links
  44. $links = '';
  45. $first = ($prevPageNum + 1);
  46. $last = $first + $cutStarting;
  47.  
  48. for ($i=($prevPageNum + 1); $i < $last; $i++) {
  49. if ($i <= $totalPages) {
  50. if ($currentPage == $i) {
  51. $links .= '[ <b>'.$i.'</b> ] ';
  52. } else {
  53. $links .= '[ <a href="?pagenum='.$i.'">'.$i.'</a> ] ';
  54. }
  55. }
  56. }
  57.  
  58. echo ' '.$links;
  59.  
  60. //calculate next link pageId
  61. $nextPageNum = ( ceil( $currentPage / $cutStarting ) * $cutStarting ) + 1;
  62. if ($nextPageNum <= $totalPages) {
  63. echo '[ <a href="?pagenum='.$nextPageNum.'">Next 5</a> ] ';
  64. }
  65.  
  66.  
  67. //get some infos for testing
  68. echo '<br /><br />Testing<hr>';
  69. echo 'Total Pages: '.$totalPages.'<br />';
  70. echo 'Current Page: '.$currentPage.'<br />';
  71. echo 'First Row: '.$firstRow;
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement