gabbo876 Posted March 19, 2013 Share Posted March 19, 2013 I'm working on a site with a large category database > 3000 categories. I have successfully loaded my category list into phpmyadmin (tables in Myisam). However when attempting to load the site (localhost), the site times out. The site times out after 30seconds and gets stuck on a subcategory count in php. Here's the line of code it gets stuck at while loading: function GetSubCatCount($catid){ global $db, $the_cats; $count = 0; foreach($the_cats as $cat){ if(isset($cat->category_parent)){ if($cat->category_parent == $catid && $cat->category__auto_id <> 0 && $cat->category_lang == $dblang) { $count = $count + 1; } } } return $count; } This counting method seems rather slow. How can I speed up the count of the subcategories in php or have Mysql send the subcategory count values? Thanks and Regards! Database: pliggTable: pligg_categories Table details: |category__auto_id |category_lang |category_id |category_parent |category_name |category_safe_name |rgt |lft |category_enabled |category_order |category_desc |category_keywords |category_author_level |category_author_group |category_votes |category_karma Software version: 5.5.25a - MySQL Community Server (GPL) Quote Link to comment https://forums.phpfreaks.com/topic/275841-quickly-count-subcategories-to-speed-up-site-loading-time/ 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.