PDA

View Full Version : Displaying picture from a mysql table


amol0010
08-17-2007, 12:18 AM
Hi,

I have a database named dmtp with tables cities and markers.

I need to display an image stored as mediumblob in markers, in dmtp.

now I am using the syntax like this -

$result = mysql_query("SELECT cities.cityname, cities.citybuslink,markers.picture, markers.information FROM cities, markers where markerid = 1 AND markers.cityid = cities.cityid

");

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" .$row['picture']. "</td>";
echo "<td>" . $row['information'] . "</td>";
echo "</tr>";


}


However, the part where the picture should be displayed shows all garbage values, any idea on how to display the actual image stored inside the database ??

Thanks

Daemonspyre
08-17-2007, 12:29 AM
Those images are stored as BINARY images, so you need to create a second PHP page that only writes out the binary data.

echo "<td>" .$row['picture']. "</td>";

Will change to

echo "<td><img src='ShowPic.php?Picture=" .$row['picture']. "' alt='' border='0'></td>";

ShowPicture.php will need to accept a querystring argument as to which picture it retrieves from the database and writes out to the screen.

As I am only a novice PHP programmer, I can only tell you how to do this in ASP, not PHP.

Someone else in the PHP forum may be able to help you.

whizard
08-17-2007, 12:39 AM
It might make more sense, if you want to, to store the path to the image in the database, which you can retrieve and put in the src attribute to put the image on your page. Especially if you have a size limit on your MySQL DB.

($0.02)

Dan