I need to execute a foreach
within another foreach
in PHP. But it returns me the following error:
Parse error: syntax error, unexpected T_FOREACH
referring to the line where the second foreach occurs
Here's 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 resolve this? Remember, I need to query in 2 different tables.