notsotechy Posted March 4, 2009 Share Posted March 4, 2009 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 More sharing options...
WolfRage Posted March 4, 2009 Share Posted March 4, 2009 Get ride of the header function. You have effectively defined to the browser that it should expect one picture and not a html document. Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776134 Share on other sites More sharing options...
notsotechy Posted March 4, 2009 Author Share Posted March 4, 2009 Thanks for the quick reply. I removed the whole line and now all I get are symbols, letters and numbers. Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776137 Share on other sites More sharing options...
WolfRage Posted March 4, 2009 Share Posted March 4, 2009 Ok just remember I do not know how you have these images stored in your database, so I don't know how to direct you in the right path. Also can you post these symbols? If you have more code can you post that as well, just screen it for any sensitive data. Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776139 Share on other sites More sharing options...
trampolinejoe Posted March 4, 2009 Share Posted March 4, 2009 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, Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776140 Share on other sites More sharing options...
notsotechy Posted March 4, 2009 Author Share Posted March 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776142 Share on other sites More sharing options...
notsotechy Posted March 4, 2009 Author Share Posted March 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776144 Share on other sites More sharing options...
trampolinejoe Posted March 4, 2009 Share Posted March 4, 2009 why dont you give each a color and pattern tag? Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776147 Share on other sites More sharing options...
WolfRage Posted March 4, 2009 Share Posted March 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776148 Share on other sites More sharing options...
notsotechy Posted March 4, 2009 Author Share Posted March 4, 2009 Very good. thank you all. Could you give me an example of a url while naming it and putting it into a category? Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776150 Share on other sites More sharing options...
trampolinejoe Posted March 4, 2009 Share Posted March 4, 2009 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' >"; } Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776155 Share on other sites More sharing options...
WolfRage Posted March 4, 2009 Share Posted March 4, 2009 Don't forget to mark solved. Also like Joe says. no matter how much you learn you'll still have alot to learn Link to comment https://forums.phpfreaks.com/topic/147880-pulling-png-pictures-from-mysql/#findComment-776222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.