chelsea, unless I'm misunderstanding you, the loop you described will have to call the page repeatedly. In simplified terms: the user clicks on a link, then sees a single photograph. Now, unless you want to use JavaScript to swap the photo out for another, they will need to click on another link - or be JavaScript redirected to the next photo. (In the latter case, it'd be good to have a link, too, for usability reasons - some people don't like JavaScript).
But this leaves you with the question of the structure for your PHP page.
This is a rough sketh of what I would do:
$_GET['page'] ? $page = $_GET['page'] : $page = 1;
$query = "SELECT filename FROM myimagexx WHERE ID='$page'";
$conn = @mysql_connect('localhost', 'user', 'pass');
if ($conn) {
mysql_select_db('dbName');
$result = mysql_query($query);
$extract($result);
print '<img src="$filename" />';
$page++;
print "<a href=\"yourscript.php?page=\"$page\">Next Photo </a>";
}
This script checks for a GET variable called page (the one that tells you which photo you want), and if it doesn't find it, sets $page to the first page: 1.
Then it gets the filename from the db, and prints the photo, increments $page, and finally, prints a link to the next photo.
Is that what you were looking for?
(NOTE: Be sure to check that $_GET['page'] is a series of 0 or more digits with a ctype_digit() (if the ctype functions are installed), or a regex function, before you assign it - otherwise someone could come along, and do some really mean stuff ....)