Jump to content

Display X images based on a number


slyte33

Recommended Posts

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 :)

 

Link to comment
https://forums.phpfreaks.com/topic/183437-display-x-images-based-on-a-number/
Share on other sites

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.

 

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++

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.