Jump to content

Search the Community

Showing results for tags 'one mysql query'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News and Announcements
    • News and Announcements
  • osCommerce Online Merchant v2.x
    • General Support
    • osCommerce Online Merchant Community Bootstrap Edition
    • Add-Ons
  • Development
  • General
    • General Discussions
    • Live Shop Reviews
    • Security
    • Developer Feedback
  • PayPal's Announcements
  • Sage Pay's Announcements
  • Solomono - new level osCommerce templates's Announcements
  • German Community's OSCOM v2.x
  • German Community's Allgemein

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Real Name


Location


Interests


Website

Found 1 result

  1. I did not and don't like the recursive function tep_get_categories() and the how the categories get drawn into the categories box. So I created a function that draws the categories tree (expanded or not). It uses only one query for the categories. So its faster than the default. It uses <ul> list tags. It produces full tree code even if $drawExpanded=false, that way you can use css3 or jquery menu so to popup on hover-click the hidden subcategories, any length of subcategories. Things to be done replace that recursive function tep_count_products_in_category when displaying the number of products under each category. Hope you like it. Check images: Tree fully expanded Tree expanded only if page in categories Produced Code Code : http://pastebin.com/puCzrASC or: //tep_draw_categories_tree function tep_draw_categories_tree($drawExpanded=false,$root_id = 0,$mainUlClass='',$submenuUlClass='submenu'){ global $languages_id,$cPath_array; //GET ALL CATEGORIES $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name"); $items = array(); while ($categories = tep_db_fetch_array($categories_query)) { $items[$categories['categories_id']] = array('name' => $categories['categories_name'], 'parent_id' => $categories['parent_id'], 'id' => $categories['categories_id']); } $citems=count($items); if($citems<=0) return ''; elseif($citems==1) $children[] = $items; //in case we have one category item without subcategories, rare but possible else foreach( $items as $item ) $children[$item['parent_id']][] = $item; // loop will be false if the root has no children (i.e., an empty categories!) $loop = !empty( $children[$root_id] ); $parent = $root_id; $parent_stack = array(); $html=array();//store html code $stack=array();//helper array so to know the current level $pic=''; //products_in_category string $html[]='<ul class="'.$mainUlClass.'">'; while ( $loop && ( ( $option = each( $children[$parent] ) ) || ( $parent > $root_id ) ) ){ if ( $option === false ){ $parent = array_pop( $parent_stack ); $html[] = str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 ) . '</ul>'; $html[] = str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 - 1 ) . '</li>'; array_pop( $stack ); }elseif ( !empty( $children[$option['value']['id']] ) ){ $tab = str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 - 1 ); $stack[]=$option['value']['id']; $rt=$root_id>0 ? $root_id.'_' : ''; $cpath_new=count($stack)<=0 ? 'cPath='.$rt.$option['value']['id'] : 'cPath='.$rt.implode('_',$stack); $html[]=$tab.'<li><a href="'.tep_href_link(FILENAME_DEFAULT, $cpath_new).'">'; if (SHOW_COUNTS == 'true') { //THIS SHOULD BE CHANGED SO NOT TO USE tep_count_products_in_category WHICH IS RECURSIVE $products_in_category = tep_count_products_in_category($option['value']['id']); if ($products_in_category > 0) { $pic=' (' . $products_in_category . ')'; } } $sm=0; if((isset($cPath_array) && in_array($option['value']['id'], $cPath_array))){ $sm=1; $html[]='<strong>'.stripslashes($option['value']['name']).'->'.$pic.'</strong>'; }else{ $html[]=stripslashes($option['value']['name']).'->'.$pic; } $html[]='</a>'; $html[] = $tab . "\t" . '<ul class="'.$submenuUlClass.'" style="'.($sm!==1 && !$drawExpanded ?'display:none;':'').'">'; $parent_stack[]=$option['value']['parent_id']; $parent = $option['value']['id']; }else{ $rt=$root_id>0 ? $root_id.'_' : ''; $cpath_new= count($stack)<=0 ? 'cPath='.$rt.$option['value']['id'] : 'cPath='.$rt.implode('_',$stack).'_'.$option['value']['id']; $html[]=str_repeat( "\t", ( count( $parent_stack ) + 1 ) * 2 - 1 ).'<li><a href="'.tep_href_link(FILENAME_DEFAULT, $cpath_new).'" >'; if (SHOW_COUNTS == 'true') { //THIS SHOULD BE CHANGED SO NOT TO USE tep_count_products_in_category WHICH IS RECURSIVE $products_in_category = tep_count_products_in_category($option['value']['id']); if ($products_in_category > 0) { $pic=' (' . $products_in_category . ')'; } } if (isset($cPath_array) && in_array($option['value']['id'], $cPath_array)) { $html[]='<strong>'.stripslashes($option['value']['name']).$pic.'</strong>'; }else{ $html[]=stripslashes($option['value']['name']).$pic; } $html[]='</a></li>'; } } $html[]='</ul>'; echo implode( "\r\n", $html ); } //tep_draw_categories_tree
×