Hi There Everyone.

Could anyone assist me in the correct method of displaying images from my mysql db. I want to display multiple images on my page.

This is the code I have. I got this from a post from DaniWeb. Hope I did the code tags correctly.


require 'library/config.php';
require 'library/opendb.php';
header('Content-type: image/JPG');

@mysql_connect($dbhost, $dbuser, $dbpass) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($dbstore) or die("Can not select the database: ".mysql_error());

$query = mysql_query("SELECT id, type, content FROM upload");
while($row = mysql_fetch_array($query)){
print $row['content'];

Thanks allot.

Member Avatar

What data type did you use for 'content?' Is it blob?
I think it would be better if you don't save the image itself on the database. Instead save just the file name and path where it was uploaded. When you have the path you can then show the images by doing <img src = '<?php echo $content ?>'>