ja_blackburn Posted October 13, 2009 Share Posted October 13, 2009 I had done a query on my database, one of the fields being an image reference to a directory where an image is stored. e.g "/images/picture.jpg" I want to display this image by using <img src= etc...> in the echo statement but am failing to get a result as i am unsure where to place " or '. Can you help? Heres my code: while($row = mysql_fetch_array($result)) { echo "<tr class='d0' valign='top'>"; echo "<td width='200'>" "<img src="'. $row['image_url'] .'.jpg>"" "</td>"; echo "<td class='large' width='300'>" . $row['title'] . "</td>"; echo "<td class='medium' width='100'>" . $row['date'] . "</td>"; echo "<td>" . $row['content'] . "</td>"; echo "</tr>"; } I know ive probably made an obvious mistake but im new to PHP. Thanks Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/ Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 use code tags next time echo "<td width='200'><img src='". $row['image_url'] .".jpg' ></td>"; you had a lot of intermingles single and double quotes for no apparent reason. close tho. this should do the trick Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936274 Share on other sites More sharing options...
taquitosensei Posted October 13, 2009 Share Posted October 13, 2009 if the extension isn't stored as part of the file name echo "<td width='200'><img src='". $row['image_url'] .".jpg'></td>"; if it is echo "<td width='200'><img src='". $row['image_url']."'></td>"; Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936275 Share on other sites More sharing options...
mrMarcus Posted October 13, 2009 Share Posted October 13, 2009 other way around .. for HTML validation purposes, always have " wrapping your tag fields, ie. *note the single quote after the echo, allows you to use double-quotations thereafter. echo '<td width="200"><img src="'.$row['image_url'].'.jpg" /></td>'; why not store the file extension (.jpg) with the filename in the db? not very practical. EDIT: added / to close <img> tag. Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936276 Share on other sites More sharing options...
ja_blackburn Posted October 13, 2009 Author Share Posted October 13, 2009 Thanks taquitosensei and others for help. Thats worked a treat - the image filenames are stored in the DB so thats even easier! Cheers Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936283 Share on other sites More sharing options...
ja_blackburn Posted October 13, 2009 Author Share Posted October 13, 2009 Had a brain wave - How would I add an anchor <a href... tag around this hyperlink the image so that people can click it and view the full size image!? echo "<td width='150'><img src='". $row['image_url']."'></td>"; Thanks! Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936306 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 by wrapping an <a> tag around it... I don't understand your question... its very simple Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936308 Share on other sites More sharing options...
ja_blackburn Posted October 13, 2009 Author Share Posted October 13, 2009 Sorry, I am learning php. I have done this, The page is displaying but no images... echo "<td width='150'><a href=". $row['image_url']."<img src='". $row['image_url']."'></a></td>"; go easy on me! Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936314 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 close echo "<td width='150'><a href='". $row['image_url']."' ><img src='". $row['image_url']."'></a></td>"; two things wrong with yours. one, you didnt end the first part of the <a> tag (so it basically would have looked like <a href=blah <img src=blah /></a> secondly, you didnt have quotes around the href attribute. Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936319 Share on other sites More sharing options...
ja_blackburn Posted October 13, 2009 Author Share Posted October 13, 2009 Thanks! Link to comment https://forums.phpfreaks.com/topic/177575-solved-displaying-an-image-using-echo-command/#findComment-936337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.