Jump to content

Want to do a loop, how can I do this?


Sam Granger

Recommended Posts

I have the following sourcecode:

<?php

$ad = $_GET['a'];

$filename = "./uploads/$ad.jpg";

if (file_exists($filename)) {
  echo "<img src='$filename' alt='' />";
}
?>

Currently when i go to filename.php?a=1 it displays 1.jpg if it exists. However, I want it to check if 1_1.jpg, 1_2.jpg, 1_3.jpg etc... exists. Lets say those 3 files exists but 1_4 doesnt, then it has to stop checking (stop the looping). How can I do this?
Link to comment
https://forums.phpfreaks.com/topic/23257-want-to-do-a-loop-how-can-i-do-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.