Loop inside another loop (while) in PHP + Smarty

0

I have a Loop (while) of the POST photos inside the POST loop.

The following is happening:

It turns out that all PHOTOS are appearing within each POST at all, rather than just the photo of each post.

In PHP:

foreach($resultado as $linha)  

    {  

       $idPost[]        = $linha['ID'];
       $codigoAnexo     = $linha['CODIGO'];
       $mensagem[]       = utf8_encode($linha['MENSAGEM']);
       $titulo[]       = $linha['TITULO'];


$con_anexo = $conn->prepare("SELECT ID,NOME FROM anexos WHERE ID_POST='$codigoAnexo'");
$con_anexo->execute();

while ($linha = $con_anexo->fetch(PDO::FETCH_ASSOC)) {
    $codAnexo[]    = $linha['ID'];
    $nomeAnexo[]   = $linha['NOME'];
}


} 

$smarty->assign("id_foto_post", isset($id_foto_post)?$id_foto_post:'');
$smarty->assign("codAnexo", isset($codAnexo)?$codAnexo:'');
$smarty->assign("nomeAnexo", isset($nomeAnexo)?$nomeAnexo:'');  

No SMARTY:

{section name=i loop=$idPost}

    <tr>

         <td>{$titulo[i]}</td> 
     <p>Descrição: {$mensagem[i]|default:' '}</p>


       {section name=a loop=$codAnexo}   
      <p>
    <img src="anexos/{$nomeAnexo[a]}"/>
    </p>

    {/section}

    </td>
     </tr>

      {/section}
    
asked by anonymous 20.05.2018 / 00:43

0 answers