Dispalying BLOB in a gallery??

0 views
Skip to first unread message

e_mann

unread,
Aug 24, 2010, 9:29:41 AM8/24/10
to Professional PHP Developers, io...@greenwich.ac.uk
Having actually uploaded images (BLOBs) into the database in MySQL. My
issue is actually displaying multiple images from the database. my
code only returns one image. Any help will be appreciated pls!!! I
have 2 different codes but same result.

**Code1***
require('connect.php');
$query = "SELECT * FROM tblImg ORDER BY id";
$result = MYSQL_QUERY($query,$link) or die(mysql_error());
$data = MYSQL_RESULT($result,0,"bin_data")or die(mysql_error());
$type = MYSQL_RESULT($result,0,"id")or die(mysql_error());
Header( "Content-type: $type");
echo $data;
// print $_FILES; displays just array on screen

?>

**Code2***
require("connect.php");
$result = mysql_query("select * from tblImg order by id DESC",$link)
or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
?>
header("Content-type: image/jpeg",false); // or whatever
echo $row['bin_data'] . " " . $row['description'];
echo "
";
}
mysql_close($link);
?>

Jack Timmons

unread,
Aug 30, 2010, 7:17:43 AM8/30/10
to professi...@googlegroups.com
On Tue, Aug 24, 2010 at 8:29 AM, e_mann <sey...@gmail.com> wrote:
> Having actually uploaded images (BLOBs) into the database in MySQL.
> My issue is actually displaying multiple images from the database.

Based on your first sentence, I think your issue is something entirely
different.

I think you're lost on handling these images.

Are you trying to call somepage.php and show both images from the
database at the same time? If so, you're on the wrong path, friend.
You see, images are files. They're not things you can just throw in
with the HTML. They have to have the right headers and everything to
display properly. What you should do first is get a separate image.php
or something to work right by itself and then start including that in
an image tag on your main page.

Second, you're not looping through the results. You're only calling
the very first row. If you want to loop, you should do something like:

require("connect.php");
$result = mysql_query("select * from tblImg order by id DESC",$link)
or die(mysql_error());

while($i = mysql_fetch_assoc($result)) {
# $i now contains the database info
}

--
Jack Timmons
@_Codeacula

Reply all
Reply to author
Forward
0 new messages