Consider a situation where you have a mysql table FLAGS with a random amount of rows
ID Language Flag1 Flag2 Flag3 Flag4
1 dutch flanders_flag.png dutch_flag.png
2 french wallonia_flag.png french_flag.png morocco_flag.png
3 english england_flag.png ireland_flag.png america_flag.png scotland_flag.png
if i want to query these rows and put them into my html i use the while loop because i never know how much rows this table FLAGS has.
<?php
$flagquery = $db->prepare ("SELECT * FROM flags");
$flagquery->execute();
while ($flagrow = $flagquery->fetch(PDO::FETCH_ASSOC)) {
?>
<div class="col-md-1 col-sm-2 col-xs-6">
<p><?php echo $flagrow['language']; ?></p>
<p><?php echo $flagrow['flag1']; ?></p>
<p><?php echo $flagrow['flag2']; ?></p>
<p><?php echo $flagrow['flag3']; ?></p>
<p><?php echo $flagrow['flag4']; ?></p>
</div>
<?php
}
?>
But as you can see in the FLAGS table you don't always have 4 flags a language so i would think you have to do a while loop inside this previous while loop to echo only the flags that are present in the FLAGS table instead of just echo all the flags even if they are empty.
Are my thoughts right? Or what would be the best way to handle my situation?