473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

display images in HTML

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
3 2026
Atli
5,058 Expert 4TB
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
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
5,058 Expert 4TB
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

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

Similar topics

5
by: david | last post by:
Can I use WriteFile methods? It seems that it does not work. For example, the following code only dispay one figure. Response.WriteFile("images/image002.jpg") Response.Write("<br><p>")...
2
by: ruby_bestcoder | last post by:
Hi Im having problem in firefox with display:none/block. I have essentially 3 li elements. In each element there are a few nested div:s. Clicking on one of the divs, makes another div to...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
9
by: Confused but working on it | last post by:
Just wanted to say thanks for the posts helping me make ths work. Added a few comments and after the readdir used a pattern match to test for ..jpg, and seems to work fine on my test setup. Maybe I...
2
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.