0
I am making this code to capture the elements of a table in my database but while executing the code foreach I get the bug and I don’t know what to do
Function to fetch data:
function listaUniformes($conexao) {
$uniformes = array();
$query = "select * from uniformes";
$resultado = mysqli_query($conexao, $query);
while($uniforme = mysqli_fetch_assoc($resultado)) {
array_push($uniformes, $uniforme);
}
return $uniforme;
}
Foreach :
<?php
listaUniformes($conexao);
foreach($uniformes as $uniforme) {
?>
<tr>
<?= $uniforme['nome']; ?>
</tr>
<?php } ?>
Error when I enter the page
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\warehouse\uniformes.php on line 21
What error is it? any message appears?
– rray
What would be the mistake?
– mcamara
Added in publication
– Luhan Salimena
$uniforme
is not an array, da aprint_r()
on it before Return.– rray
I added print_r($even) to Function and error persists
– Luhan Salimena
Showed a blank array?
– rray
No, nothing has changed
– Luhan Salimena
Missed assignment, do so
$uniformes = listaUniformes($conexao);
– rray
There, I added this code before the foreach, my Ide took out Highlight reporting an error but the page keeps reporting the Foreach error
– Luhan Salimena
is array_push a function? Where Returns?
– adventistaam
I added the array_push in the function that captures the products in the database to insert what was assigned by the $uniform variable to the $uniform array
– Luhan Salimena