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

 

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.

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.

Archived

This topic is now archived and is closed to further replies.

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