Maracles Posted April 11, 2009 Share Posted April 11, 2009 Hi, I'm following some examples in a book and executing the following code below and having a small issue. Earlier in the code I have created the $pictures array. My problem is that this example relies on the .jpg files being in the same directory as the .php file, however I want the images to be in a subfolder called '\images'. How do I point to this subfolder? I think it must simply be altering the HTML being echoed but nothing I try works. <h1>Bob's Auto Parts</h1> <div align="center"> <table width = 100%> <tr> <?php for ($i = 0; $i < 3; $i++) { echo "<td align=\"center\"><img src=\""; echo $pictures[$i]; echo "\"/></td>"; } ?> </tr> </table> </div> </body> Link to comment https://forums.phpfreaks.com/topic/153626-solved-cannot-point-filepath-to-correct-directory/ Share on other sites More sharing options...
ToonMariner Posted April 11, 2009 Share Posted April 11, 2009 <?php for ($i = 0; $i < 3; $i++) { echo '<td align="center"><img src="images/' . $pictures[$i] .'" /></td>'; } ?> Link to comment https://forums.phpfreaks.com/topic/153626-solved-cannot-point-filepath-to-correct-directory/#findComment-807248 Share on other sites More sharing options...
Maracles Posted April 11, 2009 Author Share Posted April 11, 2009 That's great, it worked. What is the difference between using ' instead of " when printing the HTML? I noticed you used this method instead of that chosen in the book. Also, as you can see in the code I posted the book recommended breaking the HTML up using \, however it never really explained why, what does this do? Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/153626-solved-cannot-point-filepath-to-correct-directory/#findComment-807251 Share on other sites More sharing options...
ToonMariner Posted April 11, 2009 Share Posted April 11, 2009 you have three methods of declaring a string - single quotes, double quotes and the heredoc syntax. if you you use double quotes then you have to escape any double quotes in your string - I just used single quote so you didn't have to do any escaping... Link to comment https://forums.phpfreaks.com/topic/153626-solved-cannot-point-filepath-to-correct-directory/#findComment-807254 Share on other sites More sharing options...
Maracles Posted April 11, 2009 Author Share Posted April 11, 2009 Ah I see, that makes sense now. Thanks again. Link to comment https://forums.phpfreaks.com/topic/153626-solved-cannot-point-filepath-to-correct-directory/#findComment-807258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.