Fetching images from database

hii everyone!

Fetching the images from database is quite different from fetching other data from the database.
so here is code for fetching the images from table.

view.php 

<?php
mysql_connect(“localhost”,”root”,””);
mysql_select_db(“test”);
$qry = “select id from image”;
$res = mysql_query($qry) or die(mysql_error());
while($row = mysql_fetch_array($res))
{
if(!empty($row[0]))
{
echo “<img src=image.php?id=’$row[0]‘ >”;
}
}
?>

image.php

<?php
mysql_connect(“localhost”,”root”,””);
mysql_select_db(“test”);
header(“Content-type:image/jpeg”);
$query = mysql_query(“SELECT img FROM image WHERE id = “.$_GET[‘id’]);
$row = mysql_fetch_array($query);
echo $row[‘img’];
?>

DB Structure of image table

db

Advertisements

2 thoughts on “Fetching images from database

  1. Thank you for the good writeup. It in fact was once a enjoyment account it. Look advanced to far delivered agreeable from you! However, how could we keep in touch?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s