I have some code that works, but is clunky and am wondering if there is a better way to do it, first the code, and then i will explain:
// repeat query 10 times
for ($i = 1; $i <= 10; $i++) {
$query = @mysql_query("SELECT fileName FROM images");
while($row = mysql_fetch_assoc($query)){
extract($row);
echo "<img src='images/images/$fileName'/>";
}
}
I would like to repeat a set of images whose file names are stored in a mySql table. The code above repeats the query 10 times. I would rather query once, then repeat the list. Is there a way to do this, either on the mySql side or in the php loop?
Thanks.
Cache all the rows from the query in an array. Loop through the cache array 10 times and print.
Of course you’ll need to sanitize the output of
$row['fileName']