Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Retrieve images from mysql database using php

                       Already you know  how to upload images to mysql database using php. Otherwise, visit upload images to mysql database using php.

Retrieve images from database:

                        Normally you can retrieve data from mysql table using php. Then you print the result. Similarly you retrieve image name from mysql database and print image name with located folder in '<img>' tag.

Consider following mysql table.



 The php script for retrieve images from mysql database is:


<?php
        mysql_connect('localhost','root','') or die(mysql_error());
        mysql_select_db('new')  or die(mysql_error());
        $q=mysql_query("select * from image where no=1 ")  or die(mysql_error());
        $res=mysql_fetch_array($q);
?>
    <img src="<?php echo 'http://localhost/upload/image/'.$res['img_name'];?>">

   
      where,
                 mysql_query() select the row which is no '1' from mysql database.
                 mysql_fetch_array() return the result an associated array. You want to know about  mysql fetch array().
                 In your img src print image name with location of image. Now you''ll get output like this:



Related Post:
Upload files using PHP
Upload multiple files or images using PHP
How to Upload images using Ajax with jQuery in PHP


This post first appeared on PHP, MySQL, JS, JQuery, Ajax, .htaccess,robots.txt, please read the originial post: here

Share the post

Retrieve images from mysql database using php

×

Subscribe to Php, Mysql, Js, Jquery, Ajax, .htaccess,robots.txt

Get updates delivered right to your inbox!

Thank you for your subscription

×