Display images from Database in PHP
Posted: Tue Jan 27, 2009 10:02 am
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.[/color]
Hello everyone
I'm stuck again on Displaying images from a Database and I hope somebody will be able to help me.
Let me explain the scenario a bit:
- the images are uploaded through a PHP upload page which moves the images in a folder of my website
- at the same time the file name is inserted into a database:
table structure:
photo_id(mediumint, auto incremented, primary key)
photo_name (varchar 255, basicallly the $_FILES["file"]["name"])
inserting the image details into the database:
So far so good:
- The image is saved on my website,
- the image name is stored in my database as imagename.jpg or imagename.gif
In my photos.php page I would like to display all the images in a while loop but I don't know how to point to the image name on the database from my page:
I tried them all:
- echo "<img src='http://www.morenafiore.com/public/upload/$row['photo_name']'
- echo "<img src='http://www.morenafiore.com/public/upload/'$row['photo_name']''
- echo "<img src='http://www.morenafiore.com/public/upload/{$row['photo_name']}'
So I hope somebody can help me understanding what I'm doing wrong
Thank you all
Morena
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.[/color]
Hello everyone
I'm stuck again on Displaying images from a Database and I hope somebody will be able to help me.
Let me explain the scenario a bit:
- the images are uploaded through a PHP upload page which moves the images in a folder of my website
- at the same time the file name is inserted into a database:
table structure:
photo_id(mediumint, auto incremented, primary key)
photo_name (varchar 255, basicallly the $_FILES["file"]["name"])
inserting the image details into the database:
Code: Select all
$filename=$_FILES["file"]["name"];
$sql="INSERT INTO nimtaz_photos (photo_name) VALUES ('$filename')";
if (!mysql_query($sql,$dbc))
{
die('Error: ' . mysql_error());
}So far so good:
- The image is saved on my website,
- the image name is stored in my database as imagename.jpg or imagename.gif
In my photos.php page I would like to display all the images in a while loop but I don't know how to point to the image name on the database from my page:
Code: Select all
<?
$query = "SELECT * FROM nimtaz_photo ORDER BY photo_id DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<img src='http://www.morenafiore.com/public/upload/".$row['photo_name']"'" />";
?>
I tried them all:
- echo "<img src='http://www.morenafiore.com/public/upload/$row['photo_name']'
- echo "<img src='http://www.morenafiore.com/public/upload/'$row['photo_name']''
- echo "<img src='http://www.morenafiore.com/public/upload/{$row['photo_name']}'
So I hope somebody can help me understanding what I'm doing wrong
Thank you all
Morena
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: