Jump to content

Php Image Syntax Question?


Guest

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>';

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

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.