I have a form with a select element that I need to populate with values from a database. Specifically, the name and id of the current users. The fetchPairs()
functi
protected function _getSelectOptions()
{
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select()->from('users', array(
'id',
'name' => new Zend_Db_Expr("CONCAT(first_name, ' ', lastname)"),
));
return $db->fetchPairs($select);
}
This is only an idea, and fully untested, but you could try to use a Zend_Db_Expr:
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select()->from(
'users',
array('id', "CONCAT_WS(' ', first_name, last_name")
);
$roleOptions = $db->fetchPairs($select);
return $roleOptions;
From the Zend_Db documentation:
Example 15.55. Examples of specifying columns containing expressions
An expression with parentheses implicitly becomes a Zend_Db_Expr.