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 Quote Link to comment 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 Quote Link to comment 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>"; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
ja_blackburn Posted October 13, 2009 Author Share Posted October 13, 2009 Thanks! Quote Link to comment 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.