selecting image from db

Nice forum :slight_smile:

I’m having trouble displaying an image I have stored in a db and copied to the filesystem.

[php]$data = mysql_query(“SELECT * FROM table_name WHERE division=‘d1’ ORDER BY date DESC LIMIT 1”);

while ($image = mysql_fetch_array($data))
{
$template->assign_var(‘D1_TABLE’, “<img src=http://www.my_site/images/”.$image[‘content’] .">");
}
// put following in to test, incase above had syntax problem
Echo “<img src=http://www.my_site/images/”.$image[‘content’] .">";[/php]

I see a broken link for the image on the page and it’s address is showing as d1.gif. The only problem is, the image within the folder is named something random like 3423452.gif.

Thanks in advance for your time.

I would be tempted to put the URL inside of speech marks (inside of the HTML) - just to make sure that the special characters inside of it are not causing problems.

Echo "<img src=\"http://www.my_site/images/".$image['content'] ."\">";

(Note the added, escaped (with a \ infront) speech marks).

Could you please provide the HTML generated by the above code snippet. This could give a better idea if the query is returning the right data and that the path being generated is correct (you can View Source on most browsers to see this).

After while $image are empty, is the condition to end the while.

Hi there,

First off, how did you save your image? Did you save it as BLOB inside your database or you have a folder containing images and you just have URL/path saved in the database?

:slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service