Display images from MySQL database using PHP help needed please !!!
-
Hi there, Please can someone help me with this issue: How do I display an image from a database showing the latest added images first (basically showing the last index to the first) I have the rest of the code what I need is how do I access the files ? eg:
?>
please help where I have put the '?'. The database is called pagination, the table is called images. There are 3 columns in the table `images`, name_id, name, image. I want to display it in descending order acording to name_id. If you could even coment with a link to a tutorial that would help I would appretiate it. Thanx alot, Josh
-
Hi there, Please can someone help me with this issue: How do I display an image from a database showing the latest added images first (basically showing the last index to the first) I have the rest of the code what I need is how do I access the files ? eg:
?>
please help where I have put the '?'. The database is called pagination, the table is called images. There are 3 columns in the table `images`, name_id, name, image. I want to display it in descending order acording to name_id. If you could even coment with a link to a tutorial that would help I would appretiate it. Thanx alot, Josh
You will have to create a seperate PHP file that is able to load the image from the database and output it to the browser. You then set the '?' in the sample code you gave to that PHP file. The PHP script that will actually present the image to the browser will be something similar to this:
Note that you have to set the correct content type or the browser won't know what it is receiving. A full tutorial on storing images in a DB can be found at http://phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html[^]
-
Hi there, Please can someone help me with this issue: How do I display an image from a database showing the latest added images first (basically showing the last index to the first) I have the rest of the code what I need is how do I access the files ? eg:
?>
please help where I have put the '?'. The database is called pagination, the table is called images. There are 3 columns in the table `images`, name_id, name, image. I want to display it in descending order acording to name_id. If you could even coment with a link to a tutorial that would help I would appretiate it. Thanx alot, Josh
You dont necessarily have to have a seperate PHP page/script serve up the image, you could base64 encode the stream and embed it into your markup as you asked. Assuming you have a variable, for example $imagestream that equals the image field from your table row access routine, you could do this:
 . ')';
?>This works well for reasonably small to medium images, but be aware of two things: The page load time is increased as the image data is encoded in the HTML (actually bloated). Be sure your mime type is correct for the image. :)