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

problem in displaying images from database

P: 5
Hi!
I am having a problem in displaying images from database.
This the code


gallery.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. if(isset($_SESSION['$signin_name'])){}
  4. //die('ERROR:'.mysql_error());
  5.  
  6. $host="localhost";  // Host name 
  7. $username="root";   // Mysql username 
  8. $password="";       // Mysql password 
  9. $db_name="task2";   // Database name 
  10. $tbl_name="imge";   // Table name 
  11.  
  12. //------------------------------------------- Building Connection ------------------------------------------//
  13.  
  14. $con = mysql_connect("$host","$username","$password");
  15. if (!$con)
  16.   {
  17.   die('Could not connect: ' . mysql_error());
  18.   }
  19.  
  20. //------------------------------------------- Selecting Database -------------------------------------------//
  21.  
  22. mysql_select_db("$db_name", $con) or die(mysql_error());
  23.  
  24. //----------------------------------------- Selecting 'Filename' form 'imge' -------------------------------//
  25.  
  26. //$get_image="SELECT Filename FROM $tbl_name  ";
  27.  
  28.         //mysql_query($get_image) or die("Error:" . mysql_error());
  29.  
  30. //$path= mysql_fetch_array($get_image);
  31.  
  32. //echo $path;
  33. //$image = stripslashes($_REQUEST[imname]);
  34. //$rs = mysql_query("SELECT Filename FROM $tbl_name WHERE filename=\"".
  35. //addslashes($image).".jpeg\"");
  36. //$row = mysql_fetch_assoc($rs);
  37. //$imagebytes = $row[imgdata];
  38.  
  39. if (IsSet($_GET['pixID'])){ 
  40. $rs = mysql_query("select Filename from imge where id= ".$_GET['pixID']); 
  41. header("Content-type: image/JPEG");
  42. while ($row = mysql_fetch_array($rs)
  43. {
  44. print $row[$imagdata];
  45. }
  46. /*gotten = mysql_query("select Filename from imge"); 
  47.     header("Content-type: image/JPEG"); 
  48.  
  49.  while ($row = mysql_fetch_array($gotten)) 
  50.     {
  51.         print $row['imgdata']; 
  52.  
  53.     } */
  54. mysql_free_result($rs); }
  55. ?>
----------------------------------------
Displaying the images in this file

your_gallery.php

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2. <head> 
  3. <TITLE>Your Image Gallery</TITLE> 
  4. </head> 
  5.  
  6. <body> 
  7. <h1>Look at this:</H1> 
  8. <?php
  9. $host="localhost";  // Host name 
  10. $username="root";   // Mysql username 
  11. $password="";       // Mysql password 
  12. $db_name="task2";   // Database name 
  13. $tbl_name="imge";   // Table name 
  14.  
  15. //------------------------------------------- Building Connection ------------------------------------------//
  16.  
  17. $con = mysql_connect("$host","$username","$password");
  18. if (!$con)
  19.   {
  20.   die('Could not connect: ' . mysql_error());
  21.   }
  22.  
  23. //------------------------------------------- Selecting Database -------------------------------------------//
  24.  
  25. mysql_select_db("$db_name", $con) or die(mysql_error());
  26.  
  27. $strSQL = "select * from imge"; 
  28. $rsPix = mysql_query($strSQL); 
  29. $numRows = mysql_numrows($rsPix); 
  30. $i = 0; 
  31.  
  32. while($i < $numRows){ 
  33. ?>
  34. <div style="width:33%: float:left"> 
  35. <img src="gallery.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/> 
  36. <?php 
  37. $i++; 
  38. ?>
  39.  
  40.  
  41. <br/><br/><a href="upload_view.html" title="Back">Back </a>
  42. </body> 
  43. </html>  
  44.  
Please help me!
Oct 19 '10 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
You haven't stated what the problem is
Oct 20 '10 #2

Shenno
P: 59
small x mark appear is image place ?

browser outputs very big strange string ?

do u use IE or FF ?

view source of page containg img tag contain the information u expected ?
Oct 20 '10 #3

P: 5
Than u all
I have upcome with the problem
Oct 21 '10 #4

Post your reply

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