Jump to content

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

 

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

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.

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!

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.

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.