<?php
$db = &JFactory::getDBO();
$query = “SELECT id, title as name,parent_id FROM #__dir_categories ”
.”WHERE published=1 and parent_id=0 ORDER BY title ASC”;
//print $query;
$db->setQuery( $query );
$categories = $db->loadObjectList();
// print_r($categories);
$query = “SELECT id, title as text,parent_id FROM #__dir_categories ”
.”WHERE published=1 ORDER BY title ASC”;
//print $query;
$db->setQuery( $query );
$products = $db->loadObjectList();
// print_r($products);
if(!count($categories) || !count($products)) $html = ‘<div>’.JText::_(‘NO Directoty’).'</div>’;
else {
foreach($products as $product){
$options[$product->parent_id][] = $product;
}
foreach($categories as $category) {
$groups[] = JHTMLSelect::optgroup($category->name);
if(is_array($options[$category->id]))
foreach($options[$category->id] as $option){
$groups[] = JHTMLSelect::option($option->id, $option->text);
}
}
$html = JHTMLSelect::genericList($groups, ‘category_id[]’, ‘class=”inputbox” size=”10″ style=”width: 95%”‘, ‘value’, ‘text’, $this->directory->category_id );
}
print $html;
?>