Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Paging
- $maxPerPage = 10;
- $cutStarting = 5;
- $prevPageNum = 0;
- //set currentPageId
- $currentPage = isset($_GET['pagenum']) ? intval($_GET['pagenum']) : 1;
- //set first row (maybee for limits in mysql query)
- $firstRow = ($currentPage * $maxPerPage) - ($maxPerPage) + 1;
- $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;
- $get_products = $wpdb->get_results($catglobal_sql, ARRAY_A);
- $count_rows = $wpdb->get_row("SELECT FOUND_ROWS()", ARRAY_A);
- $num_count = $count_rows['FOUND_ROWS()'];
- echo '<div id="results">';
- foreach ($get_products as $catglobal_2) {
- // Data Results
- }
- if (!$get_products) {
- echo '<p>There are no products matching your criteria.</p>';
- }
- echo '<div style="clear:both"></div>';
- ?>
- </div>
- <?php
- //set params
- $total = $num_count;
- $totalPages = ceil($total / $maxPerPage);
- if ($currentPage > $totalPages && $currentPage < 1) {
- $currentPage = 1;
- }
- //calculate prev link pageId
- if ($currentPage > $cutStarting) {
- $prevPageNum = floor(($currentPage - 1) / $cutStarting) * $cutStarting;
- echo '[ <a href="?pagenum='.$prevPageNum.'">Prev 5</a> ] ';
- }
- //generate number page links
- $links = '';
- $first = ($prevPageNum + 1);
- $last = $first + $cutStarting;
- for ($i=($prevPageNum + 1); $i < $last; $i++) {
- if ($i <= $totalPages) {
- if ($currentPage == $i) {
- $links .= '[ <b>'.$i.'</b> ] ';
- } else {
- $links .= '[ <a href="?pagenum='.$i.'">'.$i.'</a> ] ';
- }
- }
- }
- echo ' '.$links;
- //calculate next link pageId
- $nextPageNum = ( ceil( $currentPage / $cutStarting ) * $cutStarting ) + 1;
- if ($nextPageNum <= $totalPages) {
- echo '[ <a href="?pagenum='.$nextPageNum.'">Next 5</a> ] ';
- }
- //get some infos for testing
- echo '<br /><br />Testing<hr>';
- echo 'Total Pages: '.$totalPages.'<br />';
- echo 'Current Page: '.$currentPage.'<br />';
- echo 'First Row: '.$firstRow;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement