benji87 Posted November 2, 2006 Share Posted November 2, 2006 Hi all ive got this code to display uploaded images from a database but at the moment it will only display one image.Here is my code:[code]$gotten = @mysql_query("SELECT * FROM pix ORDER BY pid DESC");if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata];} else { $errmsg = "MySql Error!";}if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $bytes; exit (); }?><img src=?gim=1 width=80>[/code]Now i know its controlled by the 'gim' variable but im not sure on how to modify this to made it display all the images contained in the database. Any help would be great! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/ Share on other sites More sharing options...
fiddy Posted November 2, 2006 Share Posted November 2, 2006 Pls try like this:if ($_REQUEST[gim] == 1) {$gotten = @mysql_query("SELECT * FROM pix ORDER BY pid DESC");while($row = @mysql_fetch_array($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; header("Content-type: image/jpeg"); print $bytes; } else { $errmsg = "MySql Error!";}}Sorry if am wrong some where. Just felt like giviving a hint. Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-118332 Share on other sites More sharing options...
heckenschutze Posted November 2, 2006 Share Posted November 2, 2006 You can't do that... At least not in the way your thinking...Example to show all images...DisplayImage.php[code]<?php$query = sprintf("SELECT * FROM `pix` WHERE `pid`='%d'", $_GET["gim"]); // mysql injection possible, quote $_GET["gim"] (research SQL injection)$gotten = mysql_query($query) or die(mysql_error());if($row = mysql_fetch_assoc($gotten)){ $title = htmlspecialchars($row["title"]); $bytes = $row["imgdata"];}else{ $errmsg = "MySql Error!";}header("Content-type: image/jpeg");print $bytes;exit();?>[/code]Then, to show all the images...ShowAll.php[code]<?php$query = "SELECT * FROM `pix` ORDER BY `pid` DESC";$gotten = mysql_query($query) or die(mysql_error());while($row = mysql_fetch_assoc($gotten)){ echo '<img src="DisplayImage.php?gim=' . $row["pid"] . '" alt="' . htmlentities($row["title"]) . '">';}?>[/code]Hth, Note haven't tested or checked for errors :) Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-118339 Share on other sites More sharing options...
benji87 Posted November 2, 2006 Author Share Posted November 2, 2006 Thanks mate thats great! Ive got two error's. On displayimage.php it doesnt show an image just a broken image. Also in showall.php it says unexpected t_string on line 12 but ive tried putting bits here and there but it still comes up with the same error! :-[ sorry to be a pain! Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-118342 Share on other sites More sharing options...
benji87 Posted November 2, 2006 Author Share Posted November 2, 2006 Can someone please help :o( Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-118542 Share on other sites More sharing options...
fiddy Posted November 3, 2006 Share Posted November 3, 2006 Hi kindly check the script available here:http://codewalkers.com/tutorials/35/1.htmlI guess if you make some modifications you can achive what you want.[b]I did not test it [/b] Let me know how it goes... Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-118921 Share on other sites More sharing options...
benji87 Posted November 3, 2006 Author Share Posted November 3, 2006 Thanks for the link but ive already achieved what the tutorial explains. I know how to upload an image and display it. The only trouble is i want to display all the images in the database which is achievable in the code heckenschutze gave me but i cant get it to work :-\ Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-119051 Share on other sites More sharing options...
benji87 Posted November 3, 2006 Author Share Posted November 3, 2006 Ok im getting somewhere now the code that heckenschutze has given me works apart from it wont show the images or the title. Although it does draw the title as an alt attribute. Someone please help i know im almost there with this!here is the page: [url=http://www.alns.co.uk/ssrfc/showall.php]http://www.alns.co.uk/ssrfc/showall.php[/url] Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-119061 Share on other sites More sharing options...
benji87 Posted November 3, 2006 Author Share Posted November 3, 2006 Anyone please!? I really need to get this script working! Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-119146 Share on other sites More sharing options...
gmwebs Posted November 3, 2006 Share Posted November 3, 2006 You are using the incorrect case for DisplayImage.php - it should be lowercase displayimage.php. You also have a space before the id <img src="DisplayImage.php?gim= 7" alt="league"width=80 height=80> which you probably don't want. Quote Link to comment https://forums.phpfreaks.com/topic/25912-displaying-images-from-database/#findComment-119150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.