Drop Down List Syntax

luisa 18 Apr, 2011
I think I have a syntax error in the code below but can't seem to locate it. All I am getting is '.$o[name].' instead of my dropdown list. Wondering if anyone had any ideas

?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$query = "SELECT cf_id, name  FROM #__profitcentres WHERE cf_user_id = $user->id";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
echo "<option value="'.$o[cf_id].'">'.$o[name].'</option>";
}
?>
GreyHead 19 Apr, 2011
Hi luisa,

There are some mixed-up quotes in this line
echo "<option value='".$o[cf_id]."'>".$o[name]."</option>";
The PHP curly bracket syntax can be simpler in this kind of string, and quoting the array keys can avoid some PHP warnings:
echo "<option value='{$o['cf_id']}'>{$o['name']}</option>";

Bob
This topic is locked and no more replies can be posted.