0
I have a array which receives precisely 18 values. Each "key" of that array is a time and each value of this is an SQL query. I pass this array for a json file to bring the data objects I need. The problem is that this array prints multiple times and I just need it to print once with all 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, like for each select
that return 1 result, is printing the list with all arrays, if I have 2 results will print 1 array 18 positions 2 times, if 3 results, 1 array with 18 positions 3 times ... and so on.
What could be wrong with that? I’m working with symfony framework 1.4, with ORM Doctrine 1.4
This is not directly related to your question, but consider the possibility to use
json_encode
instead of concatenating this bunch of strings - your code will become more efficient and more secure.– user25930
I wonder why not use
json_encode
– Wallace Maxters