Jump to content

view all images in one page


sawalif

Recommended Posts

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();
?>

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.