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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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