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
how to display images from my database using php
Moderator: General Moderators
-
ryanfern86goa
- Forum Newbie
- Posts: 16
- Joined: Tue Sep 22, 2009 5:26 pm
Re: how to display images from my database using php
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
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++;
}
?>
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++;
}
?>
Re: how to display images from my database using php
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).