Im trying to assign a id for each image returned from the database. The id will then be put into img id. The id needs to be from the total count of the number of database rows returned.
<?php
while ($result = mysql_fetch_assoc($query)) {
$imgURL = $result['imageUrl'];
$imgID = mysql_num_rows($query);
for ($i=0; $i <= $imgID; $i++) {
}
echo"<img id =\"$i\" src=\"uploads/$imgURL\"/>";
}
?>
What i get in return is the images are displayed from the database, but instead of img id being sequential numbers (ie 1, 2, 3 etc.) it just returns me the total count. How can I get it to assign a individual number in order for each image returned?
All help is welcome. Thank you!
You don’t even need to calculate the number of rows or have multiple loops. Just let
$ibe incremented with each pass of the while loop.