valoukh Posted April 30, 2008 Share Posted April 30, 2008 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 More sharing options...
robos99 Posted April 30, 2008 Share Posted April 30, 2008 You're incrementing $photo outside of the while loop. Move it to within the brackets and it should work. Link to comment https://forums.phpfreaks.com/topic/103584-variables-to-increment-numbers-loop/#findComment-530451 Share on other sites More sharing options...
Aeglos Posted April 30, 2008 Share Posted April 30, 2008 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); Link to comment https://forums.phpfreaks.com/topic/103584-variables-to-increment-numbers-loop/#findComment-530453 Share on other sites More sharing options...
valoukh Posted April 30, 2008 Author Share Posted April 30, 2008 Perfect! Thanks. Link to comment https://forums.phpfreaks.com/topic/103584-variables-to-increment-numbers-loop/#findComment-530490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.