Advertisement:

Author Topic: High number of sql querries for Menu categories.  (Read 1673 times)

Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
High number of sql querries for Menu categories.
« on: October 22, 2013, 01:41:12 am »
 80 categories = 80 querries.
All categories and description for category  can  be extracted in 2 querries(maybe 5-7);
(No category-subdomain,default language installed).
Code: [Select]
    function category_extract()
{
$categories = Category::newInstance()-> findRootCategoriesEnabled();
$all_categories = array();
$all_relation = array();
$tree = array();
foreach($categories as $c) {
$all_categories[$c['pk_i_id']] = $c;
if($c['fk_i_parent_id']==null) {
$tree[] = $c;
$all_relation[0][] = $c['pk_i_id'];
} else {
$all_relation[$c['fk_i_parent_id']][] = $c['pk_i_id'];
}
}
if(isset($all_relation[0])) {
$tree = Category::newInstance()->toTree($all_relation[0]);
} else {
$tree = array();
}
return $tree;
}

 function categories_menu($categories = null, $depth = 0)
{
if( ( $categories != null ) && is_array($categories) ) {
echo '<ul class="drop">';
foreach($categories as $c) {
echo '<li class ="'. $c['s_slug'] .'">';
echo'<a href="'.osc_update_search_url(array('sCategory'=>$c['pk_i_id'])).'">'.$c['s_name'].'</a>';
categories_menu($c['categories'], $depth + 1);
echo '</li>';
}
echo '</ul>';
}
}
....
$cat=category_extract() ;
categories_menu($cat);