Jump to content

variables to increment numbers - loop


valoukh

Recommended Posts

Hey all. I'm trying to create an infinite list of urls by using variables to increment the numbers, and I then plan to put a limit on the list. Unfortunately I can't get more than one link! Not sure if the bit of ASP I know is confusing me.

 

<?
$photo = 0;
while($row = mysql_fetch_array($result))
  {
  echo "<a href='big/" . $row['Ref'] . " ($photo).jpg' target='_blank'><img style='border: solid 3px #000000' title='' src='sml/" . $row['Ref'] . ".jpg' /> </a>";
}
$photo = $photo + 1;
mysql_close($dbh);
?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/103584-variables-to-increment-numbers-loop/
Share on other sites

It seems you are somewhat confused  ;)

 

The loop you have there will only repeat itself as many times as results you get from the database, and the number of iterations you want seems to be unrelated to it (due to the $photo = $photo+1 part).

 

Try this:

 

while($row = mysql_fetch_array($result)) {
    //This will loop through 0 to 9999. Note that an "infinite" loop WILL timeout your script, so better make it finite.
    for ($photo=0; $photo<10000; $photo++) {  
        echo "<a href='big/" . $row['Ref'] . " ($photo).jpg' target='_blank'><img style='border: solid 3px #000000' title='' src='sml/" . $row['Ref'] . ".jpg' /> </a>";
    }
}
mysql_close($dbh);

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.