How can use select group option in joomla


$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);
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;



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s