priyank Posted April 11, 2009 Share Posted April 11, 2009 i can see characters instead of image using below code. i used blob data type for storing images in mysql. // Performing SQL query $query = 'SELECT Image FROM tableImages'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML list($Image) = mysql_fetch_array($result); echo $Image; //print or return image Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/ Share on other sites More sharing options...
iarp Posted April 11, 2009 Share Posted April 11, 2009 It seems like you've tried storing the image itself in the database. That or something else has gone wrong that i cant think of. You can't store the image itself in the database, you can store a name value and then refer to it on the servers location like http://www.exa mple.com/images/img.jpg Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807064 Share on other sites More sharing options...
priyank Posted April 11, 2009 Author Share Posted April 11, 2009 So instead of blob data type what data type should i use Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807067 Share on other sites More sharing options...
cloudy243 Posted April 11, 2009 Share Posted April 11, 2009 I would use text, but that is not your problem. What is in the database can u show us also what should be in the database is something like <img scr="http://www.forumzbb.com/forumz/pictures/logo.png> Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807072 Share on other sites More sharing options...
priyank Posted April 11, 2009 Author Share Posted April 11, 2009 This is hmtl page it has button and iframe when button is clicked it activate showImages.php which shows images <p><form action="showImages.php" method=GET target="imageFrame" name="show_Image"> <input type="submit" name=sammount value="Next" size="1"> </form> <iframe name="imageFrame" align="middle" height="600px" width="500px" border="1"> </iframe> showImage.php has $query = 'SELECT Image FROM tableImages'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML list($Image) = mysql_fetch_array($result); echo $Image; //print or return image mysql Field Type Function Null Value imageID int(100) Image blob Binary - do not edit (0 B) (Max: 65,536B) ImageDescription varchar(200) Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807083 Share on other sites More sharing options...
Philip Posted April 11, 2009 Share Posted April 11, 2009 You can store the image in the DB as a blob format. However I'd recommend against it, and just store it as a normal image If you do decide to store it in the database, you need to have a separate file that has a header with the correct file type. Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807084 Share on other sites More sharing options...
Philip Posted April 11, 2009 Share Posted April 11, 2009 Here is a sample script: <?php $id = intval($_GET['id']); // database connection here... $result = mysql_query("SELECT * FROM `images` WHERE `id` = ".$id." LIMIT 1", $conn) or die(mysql_error()); if(mysql_num_rows($result)>0) { $row = mysql_fetch_assoc($result); header( "Content-type: ".$row['filetype'].""); echo $row['image']; } ?> id would be the image id, filetype would contain the Content-type, and image would contain the blob of the image. Then in context: <img src="showimage.php?id=1" alt="some image"> Again, I'd strongly recommend just using normal images, and not storing them in the db since it would most likely cause a lot of strain on a site. Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807085 Share on other sites More sharing options...
priyank Posted April 11, 2009 Author Share Posted April 11, 2009 Thanks for help i can display images Quote Link to comment https://forums.phpfreaks.com/topic/153589-solved-display-images-with-php-mysql/#findComment-807157 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.