954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Display Images from MySQL DB using PHP

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.

<?php

require 'library/config.php';
require 'library/opendb.php';
?>
<?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.

LRNPHP
Junior Poster in Training
62 posts since Jul 2010
Reputation Points: 10
Solved Threads: 1
 

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 <?php echo $content ?>

Shinehah
Newbie Poster
23 posts since May 2010
Reputation Points: 14
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You