Hi,

I've searched this and other forums and found what are clearly the right answers for some people but not for me.

I have a database with an item table. Item has a field called image that stores a path to an image. Here is an actual example of a path in case I've done something wrong:
"/images/boards/BURA155.jpg"
without the quotes.

My code to display the image is:

$query = "SELECT * FROM item WHERE item_id = '1'";
$result = mysql_query($query);
echo "<img src ='$result'>";

All I am gettin g returned to the browser is a broken image type square. When I check it with Firebug it tells me it is returning "Resource id # 5".

Can anone tell me in simple terms what I am doing wrong?

Thanks.

Recommended Answers

All 4 Replies

I've been playing around with it and, if I move the image into the root folder and change the link in the database to the name of the file, I can get it to display. However, this isn't really what I need for my folders. So, it seems that there is something wrong with my link but I just cannot figure out what.

You are doing it wrong.. $result = mysql_query($query); This will execute the query and return the result resource. You have to then use mysql_fetch_array (mysql_fetch_row/mysql_fetch_assoc/mysql_fetch_object) !

Read it here.. http://in.php.net/function.mysql-query

$query = "SELECT * FROM item WHERE item_id = '1'";
$result = mysql_query($query);
$row = mysql_fetch_array($result); //if it returns only 1 row else use while loop
$image_path = $row['image_path'];
echo "<img src ='".$image_path."'>";
?>

Thanks for that. I now have it working.
:)

Great! Cheers :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.