slyte33 Posted November 30, 2009 Share Posted November 30, 2009 Basically I'd like to show 5 images within 2 lines; example: $images = 5; echo "<img src=>"; $images is set to 5, so echo the image 5 times I don't exactly need it for this approach, but the answer to it is all I need I thought foreach works, but I'm not sure how to do it. All help is appreciated, thanks Quote Link to comment https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/ Share on other sites More sharing options...
aeroswat Posted November 30, 2009 Share Posted November 30, 2009 i'm confused at what you are trying to do... will a simple for loop work for you? for($i=1;$i<=$images;i++) {echo "<img src=>";} Quote Link to comment https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/#findComment-968261 Share on other sites More sharing options...
slyte33 Posted November 30, 2009 Author Share Posted November 30, 2009 i'm confused at what you are trying to do... will a simple for loop work for you? for($i=1;$i<=$images;i++) {echo "<img src=>";} I'm unsure what this does and tried using it and got: Parse error: syntax error, unexpected T_INC, expecting ')' in /home/content/54/4743054/html/tbattle_findings.php on line 186 But from looking at it.. I see this is probably exactly what i'm looking for, just theres errors. Quote Link to comment https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/#findComment-968266 Share on other sites More sharing options...
aeroswat Posted November 30, 2009 Share Posted November 30, 2009 Is $images set like an integer or is it set with quotes like a string? also i left out a $ in the i++ should be $i++ Quote Link to comment https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/#findComment-968269 Share on other sites More sharing options...
premiso Posted November 30, 2009 Share Posted November 30, 2009 for is a loop that will basically loop and increment a variable for you: $images = 5; for ($i=1;$i<=$images;$i++) {echo "<img src=>";} There is a corrected version of the code. Basically it sets $i equal to 1 at the beginning and while $i <= $images (5) execute the code in the brackets, after executing increment $i by one and go back through the check....Hopefully I explained that process right lol. The correction to the original code as putting $ before the i++ Quote Link to comment https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/#findComment-968270 Share on other sites More sharing options...
slyte33 Posted November 30, 2009 Author Share Posted November 30, 2009 Ahh I see, it works fine, thank you Also, this would mean I could do this: echo "Image #$i<br>"; or if ($i == 5) { echo "This is image number 5"; } Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/#findComment-968274 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.