HI.. I have been able to save images into MYSQL database using php but I am having problems with retrieving images from mySQL ...Can anyone help thks

8 Years
Discussion Span
Last Post by veedeoo

Why don't you store the images as files on your web server and keep a link to the image in the database?

That's alot easier and it minimises the space taken up in the DB - meaning faster searches.


    $query = "SELECT picturerow,picturetyperow FROM tbladvertdetails";
    $result = mysql_query($query);
    if (mysql_num_rows($result) ==1) {

        $data = mysql_result($result,0,"picturerow"); 
        $type = mysql_result($result,0,"picturetyperow"); 
        Header( "Content-type: $type" );       
        print $data;



must have the file saved also the type of file extension in the database in two seperate rows this works fine. save this as a php file you cannot include this code in another php file it will not work you have to link to this file for it to work. example save this as pic.php <img src ="pic.php" /> took me hours to get this working but it works.
P.S you can only use this file with one picture so if you have more than 1 pic make a different file for each picture pic1 pic2 pic3 etc


I am confused on retrieving the image from mysql database using php. I wanna retrieve multiple image in right most part of the page and also want to display other text as well. Please help me... email me:: unknownrocks619@gmail.com


1.Store the absolute src of the image in your database.(eg: http://www.randomsite.com/randomimage.jpg)
2.Fetch the url using mysql and bind results to $url.
3 Create a img src in your html using a php varible as the src. (EG:<img src='<?php echo"$url";?>' />
4. Make sure you sanitize the values/or use prepared statements.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.