Jonfire Posted February 24, 2010 Share Posted February 24, 2010 We have taken on update project or website developed by others. We are PHP novices, but have successfully made most of the modifications necessary. The website has a database with multiple product lines. There's PHP code that is common on many websites that allows the user to display 6, 12, or per page per page or choose the option to view all products. The problem that we are experiencing is that one product category, which has 55 products will only display the option of 7 pages at 6 products per page, (42 products) 4 pages at 12 products per page, (48 products), or three pages at 18 products per page, (54 products). If a visitor to the site leaves the default that six products per page, they are unable to view past the first 42 products unless they click "view all" at which time all products are available for viewing. Obviously, it is undesirable to have a customer not see all the products available, unless they click view all. We have been unable to detect any anomalies in the database that would cause this one product line page to behave this way. All other product lines display the proper number of page options, and a customer can view all products by clicking page 2, page 3, etc. until all products are viewed. Any ideas on why this page would not be obtaining the correct initial count for total products? We know all the products are in the database since they all display on view all. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/193226-pagination-problem/ Share on other sites More sharing options...
Psycho Posted February 24, 2010 Share Posted February 24, 2010 Well, this appears to be your query for getting the records per page: $product_line_count = $product->db->get_row("SELECT COUNT(1) as `count` FROM `product_lines` WHERE `id_catp` = '".$_GET['id_catp']."' AND `id_cat` = '".$_GET['id_cat']."' AND `id_subcat` = '".$_GET['id_subcat']."'"); There are several items in the WHERE clause. Any chance some of those values are affecting the count? TIP: Create your querys as string variables so you can echo them to the page for debugging. At the very least it makes your code more readable. $query = "SELECT COUNT(1) as `count` FROM `product_lines` WHERE `id_catp` = '{$_GET['id_catp']}' AND `id_cat` = '{$_GET['id_cat']}' AND `id_subcat` = '{$_GET['id_subcat']}'"; $product_line_count = $product->db->get_row($query); Another possible issue: There are three different "counts": $product_line_count, $product_count & $total_itmes_count. It is unclear what the logic is behind these, but it seems $total_items_count is used in the calculation of $new_pages, which is used to display the pages. There is a function used to do that calculation [get_product_pages_parse()], so the problem could be in that function. The code do create teh actual page links is very confusing. There is a loop of $k from 1 to 3. In that loop you do a loop of $new_pages['split'][$k] to create the page links. That leads me to beloeve that the function get_product_pages_parse() is returning the total pages NOT in a single value but in three different array indexes. WTF??? Someone like arrays way too much and the code is way overcomplicated. For example, this: if($new_pages['split']['current_page_no']['section']==$k AND $new_pages['split']['current_page_no']['id']==$page_id) { echo ' <li><a href="'.$server_data['webroot'].'/products'.$page_link.'" class="page-active">'.$page_id.'</a></li> '; } else { echo ' <li><a href="'.$server_data['webroot'].'/products'.$page_link.'">'.$page_id.'</a></li> '; } // end ELSE Could be rewritten as this: $current = $new_pages['split']['current_page_no']; $li_class = ($current['section']==$k AND $current['id']==$page_id) ? ' class="page-active"' : ''; echo "<li><a href=\"{$server_data['webroot']}/products{$page_link}\"{$li_class}>{$page_id}</a></li>"; Quote Link to comment https://forums.phpfreaks.com/topic/193226-pagination-problem/#findComment-1017509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.