Print data from an array of PHP objects

0

I hit a bit with bank return using POO and MVC, and in case I'm bringing bank data where the date is equal to the current date, the problem is that I created an array of objects to store this return, and I have to display the data on another page, which is where the error is probably occurring, follow the code

DAO Code:

 function buscaEventoPorDia($data, $idUsuario){
        $stm = $this->pdo->prepare('select e.id_evento, u.nome_usuario, e.data_evento, e.descricao_evento, e.local_evento, e.prioridade_evento, e.organizador_evento from evento e inner join usuario u on e.usuario_id_usuario = u.id_usuario where e.data_evento = ? AND e.usuario_id_usuario = ?');

        $stm->bindValue(1, $data);
        $stm->bindValue(2, $idUsuario);
        $stm->execute();

        $max = $stm->rowCount();

        echo $max;

        //for ($i=0;$i < $max; $i++);

        $retornoEventos = [];       
        while ($linha=$stm->fetch(PDO::FETCH_ASSOC)){
            $retornoEvento = new Evento();
            $retornoEvento->setId($linha['id_evento']);
            $retornoEvento->setUsuario($linha['nome_usuario']);
            $retornoEvento->setData($linha['data_evento']);
            $retornoEvento->setDescricao($linha['descricao_evento']);
            $retornoEvento->setLocal($linha['local_evento']);
            $retornoEvento->setPrioridade($linha['prioridade_evento']);
            $retornoEvento->setOrganizador($linha['organizador_evento']);
            $retornoEventos[] = $retornoEvento;
        }

            return $retornoEventos;'
}

Control Code:

$retornoEvento = $userDAO->buscaEventoPorDia($date, $id_user);//$evento)

        //var_dump($retornoEvento);

        echo"<tr>"; 
            echo"<td align='center'>".$retornoEvento->getId();"</td>";
            echo"<td align='center'>".$retornoEvento->getUsuario();"</td>";
            echo"<td align='center'>".$retornoEvento->getDescricao();"</td>";
            echo"<td align='center'>".$retornoEvento->getData();"</td>";
            echo"<td align='center'>".$retornoEvento->getPrioridade();"</td>";
            echo"<td align='center'>".$retornoEvento->getLocal();"</td>";
            echo"<td align='center'>".$retornoEvento->getOrganizador();"</td>";
            echo"</tr>";'

I would like a light for who knows how to fix the for loop and create the counter or what should be the correct thing to do.

Excuse me ignorance if the question pattern is incorrect, or the question is totally stupid. =)

    
asked by anonymous 23.04.2016 / 05:37

1 answer

1

What is missing for you is to iterate your array $retornoEvento .

For this use a foreach that provides an easy way to do this:

foreach ($retornoEvento as $obj) {
  echo $obj->getId();
  echo $obj->getUsuario();
  echo $obj->getDescricao();
  echo $obj->getData();
  echo $obj->getPrioridade();
  echo $obj->getLocal();
  echo $obj->getOrganizador();
}
    
23.04.2016 / 06:18