JSHINER Posted April 29, 2007 Share Posted April 29, 2007 I have a field in my database "number_photos" and lets say for example that number is 4. I want to make it so if # of photos = 4, it will display: photo_0.jpg photo_1.jpg photo_2.jpp photo_3.jpg I was going to use foreach to do this, but it does not work / I don't think it is the correct way. So next I thought I would do: $p = # of photos $p++ To count up - but I need it to start at 0, and also need it to display the photo_0.jpg, etc. I am stuck. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/49146-solved-counting-and-displaying-accordingly/ Share on other sites More sharing options...
lalabored Posted April 29, 2007 Share Posted April 29, 2007 This might not work but I'll try! $number = 4; //The loop. for($i=0; $i<$number; $i++){ $image[$i] = "photo_".$i.".jpg"; } //Display everything. foreach{$image as $key=>$val){ echo $val."<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/49146-solved-counting-and-displaying-accordingly/#findComment-240792 Share on other sites More sharing options...
JSHINER Posted April 29, 2007 Author Share Posted April 29, 2007 Using the following: <?php $number = $page['details']['NO_PHOTOS']; //The loop. for($i=0; $i<$number; $i++){ $image[$i] = "photos[$i]=\"dir/medium/".substr($page['details']['LIST_NO'], 0, 2)."/".substr($page['details']['LIST_NO'], 2, 3)."/".substr($page['details']['LIST_NO'], 5, 3)."_".$i.".jpg\""; } //Display everything. foreach($image as $key=>$val){ echo $val."<br />"; } ?> I get the error: "Invalid argument supplied for foreach() in ... Do you know the issue? Quote Link to comment https://forums.phpfreaks.com/topic/49146-solved-counting-and-displaying-accordingly/#findComment-240804 Share on other sites More sharing options...
JSHINER Posted April 29, 2007 Author Share Posted April 29, 2007 It helps when I set the $number to the correct field Been a long day. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49146-solved-counting-and-displaying-accordingly/#findComment-240814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.