Jump to content

Recommended Posts

Hi Everyone,

 

I'm trying to figure out the correct syntax when it comes to displaying an image on my website.

 

When I hard code the number in it works but when I add the variable $id it's not working.

 

// Not working

 

echo '<div align="center"><img src="photos'. $id . rand(1,3) . '.jpg" width="250" alt="Random Image" /></div></td>';
echo '<div align="center"><img src="photos'. $id .''. rand(1,3) . '.jpg" width="250" alt="Random Image"/></div></td>';
echo '<div align="center"><img src="photos'.$id. rand(1,3) . '.jpg" width="250" alt="Random Image" /></div></td>';

echo '<div align="center"><img src="photos/'.$id.'/'.echo rand(1,n);'.jpg" width="250" /></div></td>';
echo '<div align="center"><img src="photos/'. $id . rand(1,3) . '.jpg" width="250" alt="Random Image" /></div></td>';

 

//Works but only when I hard code the number 4 (but I can't have that because every photo is in a different folder.

echo '<div align="center"><img src="photos'. '/4/' . rand(1,3) . '.jpg" width="250" alt="Random Image" /></div></td>';

 

Any help would be appreciated, thanks!

 

Hey Everyone,

 

I finally solved the problem. The correct syntax is

echo '<div align="center"><img src="photos/'. $id .'/'. rand(1,3) . '.jpg" width="250" alt="Random Image"/></div></td>';

Edited by scm22ri
Link to comment
https://forums.phpfreaks.com/topic/271716-php-image-syntax-question/
Share on other sites

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.