Jump to content

[SOLVED] Displaying an image using echo command


ja_blackburn

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.