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
https://forums.phpfreaks.com/topic/96288-view-all-images-in-one-page/
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();
?>

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)

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.