Kez323 Posted August 14, 2013 Share Posted August 14, 2013 Hey, so to display an image from a database I was using $id = addslashes($_REQUEST['id']); $image = mysql_query("SELECT * FROM store_image WHERE id=$id"); $image = mysql_fetch_assoc($image); $image = $image['image']; header("Content-type: image/jpeg"); echo $image; That worked fine to return an image via matching the id. But I want to get ALL images from the table.. I tried this: $image = mysql_query("SELECT * FROM store_image"); while($image = mysql_fetch_array($image)){ $image = $image['image']; header("Content-type: image/jpeg"); echo $image; } But did not work.. what am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/281170-phpsql-database-image-array/ Share on other sites More sharing options...
gristoi Posted August 14, 2013 Share Posted August 14, 2013 headers must be sent BEFORE anything is outputted to screen Quote Link to comment https://forums.phpfreaks.com/topic/281170-phpsql-database-image-array/#findComment-1445021 Share on other sites More sharing options...
Kez323 Posted August 14, 2013 Author Share Posted August 14, 2013 Still dont echo all from database Quote Link to comment https://forums.phpfreaks.com/topic/281170-phpsql-database-image-array/#findComment-1445023 Share on other sites More sharing options...
mac_gyver Posted August 14, 2013 Share Posted August 14, 2013 (edited) you cannot just output multiple images. each image must have an <img src=' ... ' alt=''> html tag. the URL you put into the src=' ... ' attribute must result in the correct content type being output, followed by the data for one image. to display all your images, you would need to retrieve all the id's and output each one on the end of the url in the src= ' ... ' attribute it its own <img > tag. then when the browser fetches each image in the <img > tags it finds on a page, your first script will get the id, retrieve the data, output the content type header, followed by the image data for that id. Edited August 14, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/281170-phpsql-database-image-array/#findComment-1445033 Share on other sites More sharing options...
Solution AbraCadaver Posted August 14, 2013 Solution Share Posted August 14, 2013 Assuming your original file is called image.php and you have a column in the table called name, then something like this in another file: $result = mysql_query("SELECT id, name FROM store_image"); while($row = mysql_fetch_array($result)) { echo '<img src="image.php?id='.$row['id'].'" alt="'.$row['name'].'"><br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/281170-phpsql-database-image-array/#findComment-1445056 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.