Jump to content

trying to display one field as an image...


ramboangel11

Recommended Posts

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"; 

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.