Jump to content

Pulling png pictures from mysql


notsotechy

Recommended Posts

I am trying to echo pictures from my DB.  here is the code

 

header("Content-type: image/png");

$connection = mysql_connect("localhost", "root", "root");

 

mysql_select_db("test");

 

$result = mysql_query("SELECT * FROM products");

 

    while($row = mysql_fetch_array($result))

    {

          echo $row['prod_pic'];

    }

 

This only displays the first picture in the DB.  Please help

Link to comment
https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/
Share on other sites

I have them stored in the DB as a longblog and a .png file.  I typed all the code this page has so far there is nothing else.

 

I cant post the symbols because there on a different computer.  Basically, it looks like im showing the picture, but the binary.

just an idea, I havnt really tried it.

 

But why dont you have your images uploaded directly to your server? Then in the Db have it echo html to display the image of choice?

 

Cheers,

I want to be able to have a search drop down and search by color, pattern, etc.  I thought I needed them in my DB to be able to do this.

You probably are spitting out the binary which is a problem. I have not dealt with Images in a database, because I consider it a extreme drain on a database, that just is not neccessary. Why don't you make a table with url's to the images and give them names and categories and what ever else you want. Then you can just echo the urls.

Use SQL not php to edit the which category, just add another column to your db.

 

$result = mysql_query("SELECT * WHERE category = mycategory FROM products");

    while($row = mysql_fetch_array($result))
    {
          $url = $row['pic_url'];
          $myname = $row['pic_namel']; 

          echo "<img src='$url' title='$myname' >"; 
    }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.