ramboangel11 Posted November 21, 2010 Share Posted November 21, 2010 MySQL client version: 5.0.77 My code works fine. Displays what I want. However, I want to display the "thumbnail" field as an image, rather than text. I feel like my mind is too boggled from too many tutorials, and I feel like a rookie! The name and price should be displayed as text, which they are, and the thumbnail field is displaying the image filename, and I'd like it to display the image itself. Help, please? Thank you in advance! $result = mysql_query( "SELECT name, price, thumbnail FROM s01_Products ORDER BY RAND() LIMIT 1" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/ Share on other sites More sharing options...
Pikachu2000 Posted November 21, 2010 Share Posted November 21, 2010 Since they need to echoed differently now, you may as well get rid of the foreach loop. $result = mysql_query( "SELECT name, price, thumbnail FROM s01_Products ORDER BY RAND() LIMIT 1" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; print "\t<td><font face=arial size=1/>{$get_info['name']}</font></td>\n"; print "\t<td><font face=arial size=1/>{$get_info['price']}</font></td>\n"; print "\t<td><img src=\"{$get_info['thumbnail']}\"></td>\n"; print "</tr>\n"; } print "</table>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137308 Share on other sites More sharing options...
ramboangel11 Posted November 21, 2010 Author Share Posted November 21, 2010 graphics/00000001/toysandgames.jpg was the text displaying from the thumbnail field. and i was just thinking maybe the thumbnail field should be directed to a path? now it shows a broken image in that section, and the name and price are not printing at all. >.< Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137309 Share on other sites More sharing options...
ramboangel11 Posted November 21, 2010 Author Share Posted November 21, 2010 How come none of the information is printing out now? I got rid of the foreach statement, and have them printing separately as suggested by Pikachu. Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137529 Share on other sites More sharing options...
Pikachu2000 Posted November 21, 2010 Share Posted November 21, 2010 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137533 Share on other sites More sharing options...
fenway Posted November 21, 2010 Share Posted November 21, 2010 Dump $get_info, see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137534 Share on other sites More sharing options...
ramboangel11 Posted November 21, 2010 Author Share Posted November 21, 2010 This is what I've tried with getting rid of $get_info: print "\t<td><font face=arial size=1/>{['name']}</font></td>\n"; print "\t<td><font face=arial size=1/>['name']</font></td>\n"; print "\t<td><font face=arial size=1/>$name</font></td>\n"; This is what my code looks like: $result = mysql_query( "SELECT name, price, thumbnail FROM s01_Products ORDER BY RAND() LIMIT 1" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; print "\t<td><font face=arial size=1/>{$get_info['name']}</font></td>\n"; print "\t<td><font face=arial size=1/>{$get_info['price']}</font></td>\n"; print "\t<td><img src=\"{$get_info['thumbnail']}\"></td>\n"; print "</tr>\n"; } print "</table>\n"; Nothing is printing. The image shows up as broken. Phoo. Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137546 Share on other sites More sharing options...
fenway Posted November 21, 2010 Share Posted November 21, 2010 Not literally dump -- var_dump() the output. Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137563 Share on other sites More sharing options...
Pikachu2000 Posted November 21, 2010 Share Posted November 21, 2010 Change mysql_fetch_row to mysql_fetch_assoc. Also, since you're retrieving exactly one record, the while() loop is unnecessary. Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137565 Share on other sites More sharing options...
ramboangel11 Posted November 21, 2010 Author Share Posted November 21, 2010 Thank you Fenway for your help. Pikachu2000, changing mysql_fetch_row to mysql_fetch_assoc fixed EVERYTHING! How come it's always one teeny tiny thing...You're awesome. Fantastic. You've made me ecstatic. haha. THANK YOU! Quote Link to comment https://forums.phpfreaks.com/topic/219328-trying-to-display-one-field-as-an-image/#findComment-1137577 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.