Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Display images from MySQL database using PHP help needed please !!!

Display images from MySQL database using PHP help needed please !!!

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databasehelpquestionphpmysql
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josh7harington
    wrote on last edited by
    #1

    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

    G J 2 Replies Last reply
    0
    • J Josh7harington

      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

      G Offline
      G Offline
      Gerben Jongerius
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      • J Josh7harington

        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

        J Offline
        J Offline
        Jon Heather
        wrote on last edited by
        #3

        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:

        ![?](data:image/jpg;base64,' . base64_encode($imagestream) . ')';
        ?>

        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. :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups