scm22ri Posted December 7, 2012 Share Posted December 7, 2012 (edited) 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 December 7, 2012 by scm22ri Quote Link to comment https://forums.phpfreaks.com/topic/271716-php-image-syntax-question/ 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.