Forum Moderators: coopster

Message Too Old, No Replies

Help with image display please

image display from mysql

         

Dawn

9:57 am on Dec 13, 2007 (gmt 0)

10+ Year Member



Hello,

Can anyone help me. I have this code which works fine for what I want BUT I want the row/ field to start by showing the villa image which are uploaded in my mysql database as a BLOBs stored as .gifs. I want all the images stored on the database.

The images are are in a field called 'pix' at the end of 8 other fields called villaID, villaName, villaDescription etc.. so it's simply for my which is how I need it.

What do I need to add to the script to show the image. I am not very good at all this and do not want to change what I have already as it's taken me so long to get this far and I am exhausted!

I have tried by simply adding a row and typing 'pix' but as you would have guessed it shows binary I think.

Thanks guys for your help it is very much appreciated.

<?php
$db_host = "localhost";
$db_user = "";
$db_pwd = "";
$db_name = "";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<P style="font-family: 'Papyrus'; color: #151B8D;"><b>One bedroom villas in Spain</b></p>
<table style="width: 700px; height: line-height: 50px; font-family: 'arial'; color: #151B8D; text-align: left;">
<?php
$sql = "SELECT * FROM VillaCatalog WHERE villaType = 'one bedroom'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row['villaName']."</td>";
echo "<td>".$row['villaDescription']."</td>";
echo "<td>".$row['villaCity']."</td>";
echo "<td>".$row['villaID']."</td>";
echo "</tr>";
}
?>
</table>

phranque

12:59 pm on Dec 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you want to use an img tag in your document to display the image.
the value of the src attribute of the img tag will be the url of the image, not the blob itself.
if the browser that gets your page happens to display images, it will make a subsequent request of that url to get the image.
this is when you want to return the blob, preferably preceded by some HTTP headers which properly identify it and make it look like a file if you prefer.

you could provide the image data inline by using the object tag with the data and type attributes, but that's not very friendly.

Dawn

3:32 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



Thank you.