By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

display images in HTML

P: 1
I need to display images in a page called from a database. I am new to all this so I am only pulling the binary code of the image versus the actual image. Any help would be appreicated. The code I have as of now is as follows:
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3.   $SelectID = '113';    
  4.  
  5.     MYSQL_CONNECT("localhost","db","dbpw"); 
  6.     mysql_select_db("db"); 
  7.  
  8. $sql = " SELECT * FROM ad where id = $SelectID LIMIT 1"; 
  9. $result = mysql_query($sql); 
  10.  
  11. header("Content-type: image/jpeg");
  12.   while($row = mysql_fetch_array($result))
  13.     { 
  14.   echo "
  15. <div id=\"container\">
  16. <table border=1 width=450 bgcolor=black>
  17. <tr>
  18. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[city] ,$row[state]</font></td>
  19. </tr>
  20. <tr>
  21. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[year]</font></td>
  22. </tr>
  23. <tr>
  24. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[id]</font></td>
  25. </tr>
  26. <tr>
  27. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[make]</font></td>
  28. </tr>
  29. <tr>
  30. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[model]</font></td>
  31. </tr>
  32. <tr>
  33. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[color]</font></td>
  34. </tr>
  35. <tr>
  36. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[cc]</font></td>
  37. </tr>
  38. <tr>
  39. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[mileage]</font></td>
  40. </tr>
  41. <tr>
  42. <td><font face=\"Tahoma\" size=\"1\" color=\"white\">$row[description]</font></td>
  43. </tr>
  44. <tr>
  45. <td><font face=\"Tahoma\" size=\"2\" color=\"white\">$row[price]</font></td>
  46. </tr>
  47. <tr>
  48. <td>print $row[image1] </td>
  49. </tr>
  50. <tr>
  51. </table> 
  52. </div>"; 
  53.     } 
  54.  
  55. MYSQL_CLOSE(); 
  56.  
  57. ?>
Oct 2 '08 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Hi.

You can't just echo the content of the image into the HTML.
Well, technically it could be done, but the normal way is much better at the moment.

What you want to do is use a normal <img> tag, but instead of calling an actual image it would call a .php script that acts as an image.
A browser will see no difference between a typical JPEG file and a PHP script that sets the Content-Type header to image/jpeg and echoes the content of a JPEG image.

I wrote an article about uploading and displaying files from a MySQL database in the PHP HowTo section. You can see it here.
Maybe that will help.
Oct 2 '08 #2

chelvan
P: 90
hi
to display the image just do like the normal html img tag. that will display the image.

Expand|Select|Wrap|Line Numbers
  1. <td><img src='....../$row[image1]'> </td>
chel-1
Oct 2 '08 #3

Atli
Expert 5K+
P: 5,058
hi
to display the image just do like the normal html img tag. that will display the image.

Expand|Select|Wrap|Line Numbers
  1. <td><img src='....../$row[image1]'> </td>
chel-1
That won't work if the database is returning the binary data for the image.

The src attribute of an <img> tag (by default) expects the location of the image, not the image data.
Oct 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.