Foreach returns nothing back

Asked

Viewed 90 times

-2

I have a database query that returns an object to me Array ( [0] => stdClass Object ( [id] => 3 [status] => pending [task] => drink juice )

[1] => stdClass Object
    (
        [id] => 17
        [status] => pendente
        [tarefa] => lavar pneu
    )

Only at the time of foreach to display the data on the screen, is returning only

 $tarefa){ ?>()

follow the foreach:

  <? foreach($tarefas as $indice => $tarefa){ ?>

      <?= $tarefa->tarefa?> (<?= $tarefa->status ?>)
<? } ?>

(PHP tags are why they are in the HTML file)

  • Your server PHP identifies html files as php files? What is the file extension where this code is . html or . php?

  • var_dump($tarefas); shows what ?

2 answers

-2


foreach ($stdClass as $key => $value) {
    $resp[] = $key.' - '.$value;
}

echo "<pre>";
print_r($resp);
echo "</pre>";

Array
(
    [0] => ID - 17
    [1] => STATUS - PENDENTE
    [2] => TAREFA - LAVAR PNEU
)
  • The error was in the query search parameter, so vlw msm too! xD

-2

Use the following function php to convert stdClass for array

get_object_vars($data)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.