0
How do I make projects belonging to the same department stay in the same department?
$sql = "SELECT d.nome, p.titulo FROM projeto p, departamento d WHERE p.dpto_id=d.id ORDER BY d.nome, p.titulo";
$dpto=null;
foreach ($rows as $reg){
$departamento=$reg["nome"];
$titulo=$reg["titulo"];
if($departamento!==$dpto){
echo "<section>";
echo "<h1>". $departamento . "</h1>";
echo "<p>". $titulo ."</p>";
} elseif ($departamento===$dpto) {
echo "<p>". $titulo ."</p>";
}
$dpto=$departamento;
}
//Resultdo final deveria ser assim
<section>
<h1>nome do departamento</h1>
<p>lista de projetos</p>
</section>
<section>
<h1>outro departamento</h1>
<p>sua de projetos</p>
</section>
I tried like that, but I can’t close the Section tag.
It did not work. FV and DS projects belong to Dpto1, but remained outside the section. The same happened with the ABGO and GT projects of Dpto2. Section H1 dto1 H1 XTZ Section FV DS Section H1 dto2 H1 RT Section ABGO GT Section H1 dto3 H1 YWZ Section Section Dto4 H1
– Sérgio Ramos da Silva
I updated the program, try this new way
– Geraldão de Rívia