6
I need to run a foreach
within another foreach
in PHP. But it gives me the following error:
Parse error: syntax error, Unexpected T_FOREACH
referring to the line where the second foreach occurs.
Follows part of the code:
$select = $bd -> prepare("SELECT * FROM umatabela ORDER BY id DESC");
$select -> execute();
$Fetch = $select -> fetchAll(PDO::FETCH_ASSOC);
$Conta = $select -> rowCount();
if ($Conta) {
foreach ($Fetch as $postagem) {
$oilUser = $postagem["sla"];
$selectFoto = $bd->prepare("SELECT foto FROM outratabela WHERE cond='$oilUser' LIMIT 1");
$selectFoto -> execute();
$FetchFoto = $selectFoto -> fetchAll(PDO::FETCH_ASSOC);
echo "
<a href='#'>".foreach($FetchFoto as $autorFoto) {
echo "<img src='".$autorFoto["foto"]."' alt='".$postagem["autor"]."' class='img-circulo'>";
}."</a>
}
}
How can I solve this? Remembering that, I need to make the queries in 2 different tables.
Just so I understand, what is the difference between this solution and @bfavaretto’s?
– Bacco
The difference is only by the way of doing things I keep all the images of the foreach in the variable
$fotos
and then I call the variable$fotos
to list them and only one way that clears the code– César Sousa