Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.