dynamically creating checkbox options from table, but...

Status
Not open for further replies.

usdc-or

Member
If my query to the table where I'm getting my options from returns nothing (which it should sometimes), I get one checkbox with no label. Anyway to get rid of it?

I'm using the code suggested in the checkbox element:

$db = JFactory::getDbo();
$db->setQuery('SELECT id, text FROM #__tablename');
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$options[] = JHTML::_('select.option', $row->id, $row->text);
}
return $options;

Works fine until the query returns nothing. Any assistance would be appreciated!
 
If there are no options you must return an empty array, otherwise it's displaying the defined suboptions.
Something like
...
if (!is_array($options) ) $options[]='';
return $options;
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top