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

Display image from database using php

P: 2
i have a table named tablenamevehicle which contains about 15 fields. all are text fields and one is image field stored in blob data type. I am able to display all the text from the other fields of the table but the image is being displayed as the binary data. Please help me out to display the image in its form. Code is


Expand|Select|Wrap|Line Numbers
  1.  
  2. <table width="950" align="center" border="0">
  3.   <tr align="center">
  4.     <td align="center" class="menubar1"><br/> <font size="+3">Vehicles</font></td>
  5.     </tr>
  6.     <tr>
  7.     <td>
  8. <div id="container">
  9.  
  10.  
  11. <?php
  12. /*set varibles from form */
  13. $searchterm1 = $_POST['searchterm1'];
  14. trim ($searchterm1);
  15. /*check if search term was entered*/
  16. if (!$searchterm1){
  17.         echo 'Please enter a search term.';
  18. }
  19. /*add slashes to search term*/
  20. if (!get_magic_quotes_gpc())
  21. {
  22. $searchterm1 = addslashes($searchterm1);
  23. }
  24.  
  25.  
  26.  
  27. $searchterm2 = $_POST['searchterm2'];
  28. trim ($searchterm2);
  29. /*check if search term was entered*/
  30. if (!$searchterm2){
  31.         echo 'Please enter a search term.';
  32. }
  33. /*add slashes to search term*/
  34. if (!get_magic_quotes_gpc())
  35. {
  36. $searchterm2 = addslashes($searchterm2);
  37. }
  38.  
  39.  
  40.  
  41.  
  42. /*set varibles from form */
  43. $searchterm5 = $_POST['searchterm5'];
  44. trim ($searchterm5);
  45. /*check if search term was entered*/
  46. if (!$searchterm5){
  47.         echo 'Please enter a search term.';
  48. }
  49. /*add slashes to search term*/
  50. if (!get_magic_quotes_gpc())
  51. {
  52. $searchterm5 = addslashes($searchterm5);
  53. }
  54.  
  55.  
  56.  
  57. /*set varibles from form */
  58. $searchterm4 = $_POST['searchterm4'];
  59. trim ($searchterm4);
  60. /*check if search term was entered*/
  61. if (!$searchterm4){
  62.         echo 'Please enter a search term.';
  63. }
  64. /*add slashes to search term*/
  65. if (!get_magic_quotes_gpc())
  66. {
  67. $searchterm4 = addslashes($searchterm4);
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /* connects to database */
  76.  
  77. $username="root";
  78. $password="webmaster";
  79. $database="demo1";
  80. mysql_connect("localhost","root","webmaster");
  81. @mysql_select_db($database) or die( "Unable to select database");
  82. /*query the database*/
  83. $query = "select * from tablenamevehicle where field4_name like '%".$searchterm4."%' and field5_name like '%".$searchterm5."%' and field1_name like '%".$searchterm1."%'and field2_name like '%".$searchterm2."%'";
  84.  
  85. $result = mysql_query($query);
  86. /*number of rows found*/
  87. $num=mysql_numrows($result);
  88.  
  89. mysql_close();
  90. ?>
  91.  
  92. <table border="0" cellspacing="2"cellpadding="20">
  93. <tr>
  94. <th><font face="Arial, Helvetica, sans-serif">Type of Vehicle</font></th>
  95. <th><font face="Arial, Helvetica, sans-serif">Version</font></th>
  96. <th><font face="Arial, Helvetica, sans-serif">Brand</font></th>
  97. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  98. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  99. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  100. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  101. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  102. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  103. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  104. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  105. <th><font face="Arial, Helvetica, sans-serif">Model</font></th>
  106. </tr>
  107.  
  108. <?php
  109. $i=0;
  110. while ($i < $num) {
  111.  
  112. $f1=mysql_result($result,$i,"field1_name");
  113. $f2=mysql_result($result,$i,"field2_name");
  114. $f3=mysql_result($result,$i,"field3_name");
  115. $f4=mysql_result($result,$i,"field4_name");
  116. $f5=mysql_result($result,$i,"field5_name");
  117. $f6=mysql_result($result,$i,"field6_name");
  118. $f7=mysql_result($result,$i,"field7_name");
  119. $f8=mysql_result($result,$i,"field8_name");
  120. $f9=mysql_result($result,$i,"field9_name");
  121. $f10=mysql_result($result,$i,"field10_name");
  122. $f11=mysql_result($result,$i,"field11_name");
  123. $f12=mysql_result($result,$i,"field12_name");
  124. $f13=mysql_result($result,$i,"image");
  125. ?>
  126.  
  127. <tr>
  128.  
  129. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
  130. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
  131. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
  132. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
  133. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
  134. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td>
  135. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f7; ?></font></td>
  136. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f8; ?></font></td>
  137. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f9; ?></font></td>
  138. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f10; ?></font></td>
  139. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f11; ?></font></td>
  140. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f12; ?></font></td>
  141. <td><font face="Arial, Helvetica, sans-serif"><?php echo $f13; ?></font></td>
  142.  
  143. </tr>
  144.  
  145. <?php
  146. $i++;
  147. }
  148. ?>
  149. </table>
  150. </div>
  151. </td>
  152.  
  153.  
  154.  
*/


$f13=mysql_result($result,$i,"image"); is the place where i am calling the image to be displayed
*?

help needed plesae
Jan 16 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
as AdaHacker explained, use base64 data or use an <img> tag.

PLEASE DO NOT CROSS POST YOUR QUESTION IN DIFFERENT FORUMS!
Jan 17 '12 #2

Post your reply

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