how to display images from my database using php

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
ryanfern86goa
Forum Newbie
Posts: 16
Joined: Tue Sep 22, 2009 5:26 pm

how to display images from my database using php

Post by ryanfern86goa »

hi there
I have created a table $query2="CREATE TABLE '$user1' ( id tinyint(3) unsigned not null auto_increment,
image blob not null, primary key(id))";
I have inserted quite a few pictures in it... when i try to display or fetch them i only get one picture dispalyed, thats the pic with id 1.heres my code
<? session_start(); ?>
<?php
$user1=$_SESSION["user1"];
$pass1=$_SESSION["pass1"];
@mysql_connect("localhost", "abc", "abcd") or die("Can not connect to database: ".mysql_error());
@mysql_select_db('test') or die("Can not select the database: ".mysql_error());
$query = mysql_query('select image from $user1');
$row = mysql_fetch_array($query);
$content = $row['image'];
header('Content-type:image/jpg');
echo$content;
?>

i want to display all the pictures in that database..
Any help would be appreciated.. thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how to display images from my database using php

Post by jackpf »

Use a while() loop on mysql_fetch_array().
ryanfern86goa
Forum Newbie
Posts: 16
Joined: Tue Sep 22, 2009 5:26 pm

Re: how to display images from my database using php

Post by ryanfern86goa »

hi jack
thanks for replying. do u mean this way

$row = mysql_fetch_array($query);
while($row)
{
$content = $row['image'];
header('Content-type:image/jpg');
echo$content;
$row++;
}
?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: how to display images from my database using php

Post by onion2k »

You can only display one image at a time. If you want to display all of them you'll need to make an HTML page (static or PHP, whatever) that contains lots of <img> tags, each of which gets a different image from the database (using a $_GET value with the id).
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: how to display images from my database using php

Post by jackpf »

Good point.
Post Reply