Jump to content

How to retrieve the image from MySQL?


sabo86

Recommended Posts

I have this code now (I've been editing it thousands times  ;D)

  for ($i=0; $i <$num_results; $i++){
$row = mysql_fetch_array($result);
echo " <p><strong>".($i+1).".Model: </strong>";
echo htmlspecialchars(stripslashes($row["Model"]));
echo "<br><strong> Description: </strong>" ;
echo htmlspecialchars (stripslashes($row["Description"]));
echo "<br><strong> Category: </strong>";
echo htmlspecialchars (stripslashes($row["Category"]));
echo "<br><strong> Image: </strong>";
echo $row["Picture"];}

 

How can I retrieve the image and display it in the correct place?

I've heard that storing them in blob format will exhaust mysql..

 

Link to comment
https://forums.phpfreaks.com/topic/124171-how-to-retrieve-the-image-from-mysql/
Share on other sites

What is held in the variable $row["Picture"]

 

Is it a path to an image or is it the binary code of the image itself?

 

If is the first then just output an HTML image tag to display the image, eg:

echo "<br><strong> Image: </strong>";
echo '<img src="'.$row["Picture"].'" />';}

 

However for the latter its a bit more complex as you cannot display binary data within a HTML page.

Yes, you'll need to have two images for this to work. The actual image itself and a smaller version of the original image for the thumbnail. You'll then do something like this:

echo "<br><strong> Image: </strong>";
echo '<a href="'.$row["Picture"].'"><img src="'.$row["PictureThumbnail"].'" /></a>';}

 

The code will not work until you have field in your database called PictureThumbnail -- this will hold the path to the thumbnail for the image.

one more question before i try the automated thing..

 

I created an attribute for the thumbnail... and Now i have the following result ..

resud3.jpg

 

and i want to make it in this way:

 

http://img382.imageshack.us/my.php?image=res2kn9.jpg

 

How can I edit my code?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.