Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

display image from a mysql table

images php coding issues or problems here.

Moderators: macek, egami, gesf

display image from a mysql table

Postby bghodsi » Sat Dec 31, 2011 6:33 am

Hi Folks:
Database: databaseimage
Table: store
Fields: Three(id, name and image)...Image as blob.

The following php script works as far as loading and showing one image at a time.
Can anyone show me how to display all images in the table? The script as it is written
loads and displays image 4.

<?php
$num=3;
header("Content-type: image/jpeg");
$conn=mysql_connect("localhost","root","");
mysql_select_db("databaseimage") or die(mysql_error());

$sql="SELECT image FROM store";
$result=mysql_query($sql) or die("Invalid Query:" . mysql_error());
while($row=@mysql_result($result, $num ,'image')) {
echo $row;
exit;
}

mysql_close($conn);
?>
bghodsi
New php-forum User
New php-forum User
 
Posts: 3
Joined: Tue Nov 29, 2011 1:37 pm

Re: display image from a mysql table

Postby thandono » Tue Jan 03, 2012 1:16 pm

Separate code into two php files?

main.php
Code: Select all
... //mysql connect
$sql="SELECT id FROM store";
$result=mysql_query($sql) or die("Invalid Query:" . mysql_error());
while($row=@mysql_result($result, $num ,'id')) {
  echo '<img src='image.php?ID=$row'/>';
  exit;
}


image.php
Code: Select all
Header("Content-type: image/jpeg");
$ID = $_GET['ID'];
... //mysql connect
$sql="SELECT image FROM store WHERE id=$ID";
$result=mysql_query($sql) or die("Invalid Query:" . mysql_error());
while($row=@mysql_result($result, $num ,'image')) {
  echo $row;
  exit;
}
thandono
New php-forum User
New php-forum User
 
Posts: 44
Joined: Sun Jan 01, 2012 3:06 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron