<?php
$con = mysql_connect("localhost","root","" );
mysql_select_db("test",$con);
$sql="select image from image";
$res=mysql_query($sql) or die(mysql_error());
$i=1;
while($i < mysql_num_rows($res))
{
$image_id[$i] = mysql_result($res, $i);
echo "<img src=\"".$image_id[$i]."\">";
$i++;
}

?>

I'm using this code to display the image from mysql
but images are shown like this
M¢—‡¤6n幆J1³ŒªÌF·æFLùp1 `‘ã:ÃDVNÒ–¢QSgWñg€?´‘íx3²ûEùÝ ô.l%·ËìÈŒÿAzH­'óÀËË€XƒÍ«L²GçÚ›9ást¸°äŒëŸ]˜¦21ŒÖ|¸E^®ÏJOXX&æàߣéü6bêæ¬Öò7aúQ¡·÷9;Ó-ˆ )ôdx¹cüÖlÒ'j( q1ÌnéW4Ó÷dÇå©uF
Any body please help me whats the error in that code

assuming your image table had fields image AND also id:

<?php
$con = mysql_connect("localhost","root","" );
mysql_select_db("test",$con);

if( isset($_GET['id']) && is_numeric($_GET['id']) && intval($_GET['id'])>0 )
{
	$sql="select image FROM image where id=" . intval($_GET['id']) . ' LIMIT 1';
	$res=mysql_query($sql) or die(mysql_error());
	$row=mysql_fetch_assoc($res);
	header('Content-Type: image/jpeg');
	echo $row['image'];
	exit;
}
else
{
	$sql="select id FROM image";
	$res=mysql_query($sql) or die(mysql_error());
	while( $row=mysql_fetch_assoc($res) )
	{
		echo '<img src="'.$_SERVER['PHP_SELF'].'?id='.$row['id'].'" alt="" />';
	}
}
?>

Hi it works but all images in database are shown wat to do i want to show particular image from database.

hielo's example is actually calling itself (see the url in line 20) to retrieve and display the images. The loop that displays all the images is just there as a proof of concept. In practice, the second half (no id was passed) should return an http 404 error: header("HTTP/1.1 404 Not found");

wat to do i want to show particular image from database.

You need to know the id of the image you are interested in ahead of time. So if you know that you are interested in the image whose id=3, assuming that the code I posted above is named imageRetriever.php, then in you HTML page you need to put:

<img src="http://yoursite.com/imageRetriever.php?id=3" alt="" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.