I have the following code for a <select> on a form.
$query = $em->createQuery("SELECT g.name, g.id FROM SSMURBS\Group g ORDER BY g.name ASC");`
$groups = $query->iterate();`
$groups_option = "";
foreach( $groups as $row ){
$group = $row[0];
$groups_option .= "<option val=\"{$group['id']}\">{$group['name']}</option>\n";
}
But this throws an error. What works is…
$query = $em->createQuery("SELECT g.name, g.id FROM SSMURBS\Group g ORDER BY g.name ASC");
$groups = $query->iterate();
$groups_option = "";
$i = 0;
foreach( $groups as $row ){
$group = $row[$i];
$groups_option .= "<option val=\"{$group['id']}\">{$group['name']}</option>\n";
$i++;
}
Am I doing something wrong? The reference manual cites the first option as correct…
I found the answer to my own question:
While DQL permits
SELECT g.id, g.namewithout throwing an error, this is actually SQL, not DQL. (Thanks, doctrine reference manual, for being so clear on this…)The correct way to code this is
}