1
I’m having trouble with logic maybe.
So here’s the thing:
$secao="select distinct seccao from foto";
$manda= mysqli_query($ligacao, $secao);
$array_sec=array();
while (($recebe= mysqli_fetch_assoc($manda))!=null){
array_push($array_sec, $recebe["seccao"]);
}
$re=count($array_sec);
$sql = "select imagem, seccao from foto order by seccao desc";
$resultado = mysqli_query($ligacao, $sql);
for($i=0; $i<$re; $i++){
echo '<ul>';
while (($registo = mysqli_fetch_assoc($resultado)) != null) {
if($registo["seccao"]==$array_sec[$i]){
echo "<li><a href=\"img/galeria/".$registo["seccao"]."/" . $registo["imagem"] . "\" data-smoothzoom=\"group1\"><img src=\"img/galeria/".$registo["seccao"]."/" . $registo["imagem"] . "\" width='188' height='119'></a></li>";
}
}
echo '</ul>';
}
In the first query I will fetch the sections or categories and store them in an array, do Count to know the size of it. Then I do the second query that is to fetch all the images and their respective sections.
Finally I do a cycle where I go through the size of the array I measured using Count and then do the while where I will go through all the images received by the second query. I do a check to see if the for section equals the while cycle section or the image section, the problem here is that the first <ul>
does well, but then the rest does not.
The goal was to get all the images of each section into one <ul>
different.
Felipe, what’s the mistake? The query works?
– Lollipop