Doctrine foreach query - what is wrong?

593 Views Asked by At

I have an array called $zip_in_distance

Array ([0] => Array([zip] => 12345, [distance] => 12345)).

If I am going to print the $value[zip], it is correct. But I get an empty array back. When I don't use a foreach-loop and I manually do the query, it is working. What am I doing wrong?

    $shop = array();
    foreach ($zip_in_distance as $key => $value) {

    $q = Doctrine_Query::create()
                ->from('market m')
                ->where('m.zip = ? ', $value['zip'])
                ->execute();

    $shop[] = $q;
    }
    return $shop;

My template:

foreach ($shops as $key => $list) {
   echo  $key . $list['id'] . '<br>'; 
}

I do have more than on market per zipcode. Thanks in advance!

Craphunter

1

There are 1 best solutions below

0
On

Why use a foreach at all? Try something like this:

return MarketTable::getInstance()
  ->whereIn('m.zip', array_map(
    function($element) {return $element['zip'];},
    $shop
  ))
  ->execute();