bdarilek Posted November 23, 2008 Share Posted November 23, 2008 Help!! I'm a newbie with a problem displaying my images that are stored in the database. I can upload and actually view an image but from only the first row. The information from the other rows displays just fine. I just can't get the right image to display with the rest of the corresponding fields. It only show the image from the first record. Below is my code: <?php $dbcnx = mysql_connect("localhost", "xxxxxxxx", "xxxxxx"); mysql_select_db("xxxxxxx"); $request = @mysql_query("select * from profiles"); while ($row = @mysql_fetch_assoc($request)) { if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $row['c_photo']; exit (); } echo "<img src=?gim=1><br>". "Name :{$row['c_first']} {$row['c_last']}<br>". "Email :{$row['c_email']} <br>". "Phone :{$row['c_phone']} <br><hr><br><br><br>"; } ?> Thanks for any help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/ Share on other sites More sharing options...
waynew Posted November 23, 2008 Share Posted November 23, 2008 Please use the code tags! Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697205 Share on other sites More sharing options...
GingerRobot Posted November 23, 2008 Share Posted November 23, 2008 You shouldn't be storing the actual image in your database - you should store the path to where it is on your server. You then echo out an image tag with the path, which can be done inside the loop just like the other data. Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697213 Share on other sites More sharing options...
waynew Posted November 23, 2008 Share Posted November 23, 2008 Exactly as GingerRobot stated. Databases don't handle the storing of large file sizes too easily. Displaying images takes longer. Deleting images from the database causes fragmentation. In fact, some web hosts are against it altogether. Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697216 Share on other sites More sharing options...
bdarilek Posted November 23, 2008 Author Share Posted November 23, 2008 i've looked online for a good easy tutorial. Could you recommend one? Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697220 Share on other sites More sharing options...
sasa Posted November 23, 2008 Share Posted November 23, 2008 create another script for pull images from database and pass to it key from database row Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697222 Share on other sites More sharing options...
waynew Posted November 23, 2008 Share Posted November 23, 2008 Well, it's pretty easy. Firstly, upload the picture as usual. Then make a note of its directory. For example, it could be "images/example.jpg". Store that in your database. Then print it out. Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697223 Share on other sites More sharing options...
bdarilek Posted November 23, 2008 Author Share Posted November 23, 2008 I guess I should have mentioned they are in a LongBLOB. So I don't have a directory. Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697225 Share on other sites More sharing options...
waynew Posted November 23, 2008 Share Posted November 23, 2008 Sorry, I wasn't being very clear: Upload image to a directory on the actual file system. Take note of where it is and what it is, and store it in your database. Then, for example: $get_image = mysql_query("SELECT image_directory FROM images WHERE image_id = $example") or die(mysql_error()); $image_directory = mysql_fetch_row($get_image); echo '<img src="'.$image_directory.'" alt="Whatever, maybe a caption?" />'; The column image_directory could hold the location of an image on your web server. So, image_directory could be: "images/example.gif". Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697270 Share on other sites More sharing options...
waynew Posted November 24, 2008 Share Posted November 24, 2008 Whoops: $get_image = mysql_query("SELECT image_directory FROM images WHERE image_id = $example") or die(mysql_error()); $image_directory = mysql_fetch_row($get_image); echo '<img src="'.$image_directory[0].'" alt="Whatever, maybe a caption?" />'; Quote Link to comment https://forums.phpfreaks.com/topic/133937-help-displaying-images-in-loop-stored-in-mysql-database-row/#findComment-697311 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.