tahakirmani Posted December 21, 2012 Share Posted December 21, 2012 Hi, There are 10 records in my table who have id=10, I am trying to print all the records from this table where id=1. I have written the following code, but it is showing only the last inserted record not all the records. I used foreach loop and it starts giving me an error message. <?php mysql_connect('localhost','root',''); mysql_select_db('a_database'); $query= "SELECT * FROM email_images where id=1" ; $query_run= mysql_query($query); $result= mysql_fetch_assoc($query_run); $result=$result['name']; foreach ($result as $output) { echo $output; } ?> Warning: Invalid argument supplied for foreach() in F:\xampp\htdocs\Email_address\multiple_images.php on line 13 Thanks, Taha. Quote Link to comment https://forums.phpfreaks.com/topic/272248-fetching-print-multiple-records-from-a-table/ Share on other sites More sharing options...
tahakirmani Posted December 21, 2012 Author Share Posted December 21, 2012 My Above mention problem has been solved, and now i am facing a new problem. I am trying to print all the images which are in database. I am using the following code and its printing out the code of images but not images when i am using header function its giving me an error message. Kindly tell me where to use the header function. <?php mysql_connect('localhost','root',''); mysql_select_db('a_database'); //$current_id= $_SESSION['user_id']; $query= "SELECT * FROM email_images where id=1" ; $query_run= mysql_query($query); while ($result= mysql_fetch_assoc($query_run)) { $result=$result['name']; //foreach ($result as $output) { // echo $output; echo $result; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/272248-fetching-print-multiple-records-from-a-table/#findComment-1400731 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2012 Share Posted December 21, 2012 Each image you put onto a web page must have its own HTML <img src='url_that_corresponds_to_the_image' alt=''> tag. The url_that_corresponds_to_the_image would be a url to a .php file (image.php for example) that outputs the content-type header, followed by the image data for one image. Since you would want this same .php file to work for each possible image, you would put a GET parameter on the end of the url that specifies the id of the image (image.php?id=123 for example.) Why have you stored images in a database? If you had stored the images as files in the file system and stored the file name in the database, all you would need to do is output the file names as the url_that_corresponds_to_the_image in the <img ...> tags. Quote Link to comment https://forums.phpfreaks.com/topic/272248-fetching-print-multiple-records-from-a-table/#findComment-1400734 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.