Print an array with multiple data from a select, once

0

I have an array that receives precisely 18 values. Each "key" of this array is a time and each value of this is an SQL query. I pass this array to a json file to bring the data objects I need. The problem is that this array prints several times and I only need it to print once with all the selects.

.... action....

$selectDezenove = Doctrine::getTable('Atendimentos')->createQuery('a')
                                ->where('time(a.data_hora) =', $this->horarios ); 
    $this->horarios = array();
        $this->horarios["08:20"] = $selectDezenove;
        $this->horarios["08:40"] = $selectDezenove;
.....
.... json.php ...

 foreach($horarios as $horario => $atendimento)
{
    foreach($records as $atendimento)
    {
        if( date("H:i", strtotime($atendimento->getDataHora())) === $horario )
        {
         $list[] =
                '{'."\n".
                '   "id":'.  $atendimento->getId().','."\n".      
                ' "cell":'."\n". 
                '           ['."\n".
                    '                   "'.$atendimento->getId().'",'."\n". 
                    '                   "'.$horario.'",'."\n".
                         ++dados+++
        }
        else 
        {
            $list[] =
                '{'."\n".
                '   "id":'.$atendimento->getId().','."\n".      
                ' "cell":'."\n". 
                '           ['."\n".
                    '                   "",'."\n". 
                    '                   "'.$horario.'",'."\n". 
                   ++dados++
         }
         if($atendimento == NULL )
         {
           $list[] =
                    '{'."\n".
                    '   "id":'.$atendimento->getId().','."\n".      
                    ' "cell":'."\n". 
                    '           ['."\n".
                        '                   "",'."\n". 
                        '                   "'.$horario.'",'."\n".
                        +++dados+++
          }
        }
       }
      }
     ....... fim json .....

The problem is that my result is being printed many times, type for every% of_content that returns 1 result, is printing the list with all arrays , if I have 2 results it will print 1 array of 18 positions 2 times, if you have 3 results, 1 array with 18 positions 3 times ... and so on.

What can be wrong about this? I'm working with the symfony 1.4 framework, with ORM Doctrine 1.4

    
asked by anonymous 15.06.2015 / 15:39

1 answer

1

What he printed is the $ records array information, what is happening is that the $ schedule array is larger than the $ records array and it is within the foreach that percore $ schedules. For example the array $ schedules has 2 positions, that is, its foreach will run twice. And your $ schedule array is inside that foreach only has one position and as it is inside the first foreach it does the loop twice it will repeat its result.

Q: I do not know if you could understand but I hope I have helped!

    
15.06.2015 / 17:23