By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

how do i display an image from the database?

P: 2
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
Feb 27 '08 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
Have a look at this tutorial.
Feb 27 '08 #2

ronverdonk
Expert 2.5K+
P: 4,258
Welcome to TSDN!
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
Feb 27 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 27 '08 #4

P: 2
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
Feb 27 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
Look at the thread I showed you in my previous post. Exactly the same problem.

Ronald
Feb 27 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.