DjibJoker DjibJoker - 1 year ago 93
MySQL Question

Symfony Query in controller

$query = $em->query("SELECT as id from collectif c, zone z where c.zone_id = and z.label = '$zone' and c.collectif = '$collectif' ");

$c = $query->fetchAll();
$idc = $c['id'];

I have this query that returns a single line, Symfony shows me an error as what variable id undefined

NB: I know that's don't respect the concept of Symfony [MVC] but it's for a particular reason so if someone can tell me how I can resolve this problem

Thank you

Answer Source

$query->fetchAll() should return numeric array of elements so key id does not exists. You should try $c[0]['id'] to get value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download