Click to See Complete Forum and Search --> : Picture gallery using php and mysql
matty_y2002
08-01-2006, 09:35 AM
hi, i am currently designing a website, and on one of my pages i want a gallery of pictures that originally have been uploaded by users of the websites to a table in mysql. how do i get the pictures from mysql to appear on my website. My table is called Pictures. I want the pictures to appear on the website in a order of newest first. can anyone help? Thanks Matt
Doc Thirst
08-01-2006, 11:08 AM
There are much better ways to do this I'm sure. However, I would go for the easy out.
Create a table, photos, that contains the following columns:
ID
Filename
Uploaddate
And a directory, photos, for instance.
Then you can just do a:
$recordset = mssql_query ("select * from photos order by uploaddate", $handle);
while($arr = mssql_fetch_row($recordset))
{
$id = trim($arr[0]);
$filename=trim($arr[1]);
$uploaddate=trim($arr[2]);
echo "<img src=photos/$filename>";
}
DaiWelsh
08-01-2006, 11:10 AM
Are the filenames in the database and the file son disk, or is the actual binary data of the image in the database? If it is the former then the above post gives you the nub of it, otherwise it is a little more complicated as you will also need a script to pass the image data back to the browser after pulling it from the database.