Link to home
Create AccountLog in
Avatar of nushahid
nushahidFlag for Pakistan

asked on

Showing images stored in mysql using php

Hi,

I want to show all images (stored in mysql database) in a HTML table using PHP. Please help me that how it should be possible...???

Thanks
Avatar of waygood
waygood

run a query to list all images and put the name (and location if not in current folder) as the source (SRC) of an image tag:-


<?php
// assume already connected
$result="SELECT * FROM images";
while($row=mysql_fetch_assoc($result))
{
  echo '<img src="'.$row['image_name'].'"/>';
}
?>
If image (source code of image) is stored in database (not just the filename) use an external php script to load them, modify at your convenience:

<img src="imageloader.php?imageid=<?=$row['imageid']?>">

====== imageloader.php =======
<?
$query = "select image,i_filetype from images where image_id = '". $imageid ."'";
$result = @MYSQL_QUERY($query);

$data = @MYSQL_RESULT($result,0,"image");
$type = @MYSQL_RESULT($result,0,"i_filetype");

header('Content-type: ' . $type);
echo $data;
?>
doh!    $result=mysql_query("SELECT * FROM images");

I dont advise storing images in a database. I did it for my first website and it was more trouble than it was worth
out of curiosity, waygood, why was it more trouble then it was worth?
I use images in my db, and it has made my life so much easier.
Avatar of nushahid

ASKER

Chorch gives the way of showing only one image.
If i want to show more than one image then what i have to do...???
Chorch gives the solution of showing only one image.
If i want ot show more than one image then what i have to do for that...???
ASKER CERTIFIED SOLUTION
Avatar of nplib
nplib
Flag of Canada image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
nplib: Size of Database became very large and backup scripts I wrote, took too long to execute (although I have a better way now). Moving the site to another server was a pain (internet was slower a few years back so file transfer was slower).