Connecting Tech Pros Worldwide Forums | Help | Site Map

how do i display an image from the database?

Newbie
 
Join Date: Feb 2008
Location: boston
Posts: 2
#1: Feb 27 '08
Hello I am new to the database world and Ive learned how to do a few things storing text is easy. i found that out but trying to get an image to show up on a page is difficult and i cant seem to find the correct way to call it up in php so it will display..What i am trying to do is build a search engine for a furniture companys rug collection...so that the rug type style size and an image next to that will show up...

this is my php code
[php]<?php # rug search_results.php
$connection = mysql_connect('*', '*', '*') or die(mysql_error());
if (!$connection) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("rugs", $connection);
$rugtype_id = "";
if (isset($_GET['rugtype_id'])) {
$rugtype_id = $_GET['rugtype_id'];
}
if ($rugtype_id != NULL) {
$query = "SELECT * FROM rugs WHERE rugtype_id=$rugtype_id";
$result = mysql_query($query, $connection);
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "{$row['itemnumber']}";
echo "<br />";
echo "{$row['rugname']}";
echo "<br />";
echo "{$row['origin']}";
echo "<br />";
echo "{$row['fabric']}";
echo "<br />";
echo "{$row['image']}";

} // End of WHILE loop.
}
else { // No
echo '<p class="error">';
echo "There are no rugs listed for the given request.";
echo "</p>";
}
}
else {
echo '<p class="error">';
echo "Please select a valid rug type from the drop-down menu in order to view the rugs.";
echo "</p>";
}
?>[/php]please tell me what im doing wrong any input would help thanks

Dan

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Feb 27 '08

re: how do i display an image from the database?


Have a look at this tutorial.
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#3: Feb 27 '08

re: how do i display an image from the database?


Welcome to TSDN!
Quote:
please tell me what im doing wrong any input would help thanks
What you are doing wrong anyway is NOT enclosing your code within coding tags! You make it hard on our members to help ytou when you present them with messy formatted code.

See the Posting Guidelines.

moderator
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Feb 27 '08

re: how do i display an image from the database?


Your thread title is 'How to upload an image blob', but from your code the image is already in the database and your question is about displaying an image.

If the latter is the case, you should have a look at thread Showing an image from the database because that handles this problem.

Ronald
Newbie
 
Join Date: Feb 2008
Location: boston
Posts: 2
#5: Feb 27 '08

re: how do i display an image from the database?


thanks to all

yes the image data is already in the blob. But all i seem to be getting back is what looks like binary data and not the actual image..i would love to know if there is a way in php to bring up the image. Most of the tutorials i found are how to browse and add an image to a database...i just want people to do a search and then have the image of the item and details about the item to come up. so far i can get the details to show up but im having zero luck on getting the actual image to show.

thanks
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#6: Feb 27 '08

re: how do i display an image from the database?


Look at the thread I showed you in my previous post. Exactly the same problem.

Ronald
Reply