sawalif Posted March 15, 2008 Share Posted March 15, 2008 Hi, I need help in this code ,,, I have table named subject ,in this table i have four fields (id int(9) auto_increment PK, ImageTitle varchar(30), ImageSubject TEXT and Image mediumblob) I want display all fields in one webpage to show me the Title ,Subject and the image! In this code i can't run the webpage with the image! it's running without Image when i remove //echo $result2['Image']; Thank you //view all subjects with the images. <?php include ("condb.php"); $query="select * from subject "; $result=@mysql_query($query,$con); $result = mysql_query($query) or die('Error, query failed'); while ($result2 = mysql_fetch_array($result)) { echo $result2['ImageTitle']; echo"<br/>" ; echo $result2['ImageSubject']; echo"<br/>" header("Content-type: image/jpeg"); echo $result2['Image']; echo"<hr/>" ; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
syed Posted March 15, 2008 Share Posted March 15, 2008 Hi sawalif Are you storing your images into the image field as binary? Quote Link to comment Share on other sites More sharing options...
JD* Posted March 16, 2008 Share Posted March 16, 2008 As far as I know, you cannot use the "header" function after you have already sent data. What you want to do is this: //view all subjects with the images. <?php include ("condb.php"); $query="select * from subject "; $result=@mysql_query($query,$con); $result = mysql_query($query) or die('Error, query failed'); while ($result2 = mysql_fetch_array($result)) { echo $result2['ImageTitle']."<br />".$result2['ImageSubject']."<br /><img src=\"".$result2['Image']."\" /><hr />"; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
sawalif Posted March 16, 2008 Author Share Posted March 16, 2008 Thank you JD* for your replaying me I tried your code but still same problem! The image not appeared in the webpage, maybe because I'm saving the image as binary. So please I need someone help me.. Thank you create table subject (Id int(9) primary key auto_increment, ImageTitle varchar(30),ImageSubject text,Image mediumblob) Quote Link to comment Share on other sites More sharing options...
JD* Posted March 18, 2008 Share Posted March 18, 2008 O.k., in that case, I would say you need a second page (call it image.php), that will accept an ID and do this: [code]<?PHP if(isset($_GET['id'])) { include ("condb.php"); $query="select * from subject WHERE ID = '".$_GET['id']."'"; $result=@mysql_query($query,$con) or die(mysql_error()); header("Content-type: image/jpeg"); echo $result['Image']; } else { echo ''; } ?> And then, on your main page, do: //view all subjects with the images. <?php include ("condb.php"); $query="select * from subject "; $result=@mysql_query($query,$con); $result = mysql_query($query) or die('Error, query failed'); while ($result2 = mysql_fetch_array($result)) { echo $result2['ImageTitle']."<br />".$result2['ImageSubject']."<br /><img src=\"image.php?id=".$result2['ID']."\" /><hr />"; } mysql_close(); ?> That (or something very similar) should work for you.[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.