Tuesday, July 5, 2011

Re: [phpXperts] Picture(blob) and Other's information not show together that is in Database

 

whenever u use this line - 


header("Content-type: image/jpg");

the entire content you render on browser will be assumed jpg image content.

So, if you need to show image as well as other info you will have to apply other way.

like <img src="image.php?id=".$id />, where image.php will take the id and render the jpg image that can be used by the <img /> tag to display it.

On Tue, Jul 5, 2011 at 4:06 PM, arif_php_duet <arif.rahman1988@yahoo.com> wrote:
 

Suppose Database contain:
ID Name Image
1 Arif [BLOB - 15.6 KB]
2 Imran [BLOB - 15.7 KB]
3 Sazal [BLOB - 17.7 KB]

Code for display ID,Name & picture :
<?php
$id = $_POST['id'];
if($_POST['Submit'])
{
if($id)
{
$cn = mysql_connect('localhost', 'root', '');
if($cn)
{
$db = mysql_select_db('mypicture', $cn);
if($db)
{
$sql = "select ID,Name,Image from picture where ID=".$id;
if($result = mysql_query($sql, $cn))
{
$row=mysql_fetch_row($result);
print $row[0]."&nbsp;".$row[1]."&nbsp;"; //for display Id and Name
$content = mysql_result($result,0,"Image");
header("Content-type: image/jpg");/*Display image on the browser*/
print $content;
}
}
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<label>Enter your Id:<br>
<input name="id" type="text" id="id" value="<?php print $id; ?>">
<input type="submit" name="Submit" value="Show">
</label>
<br>
</form>

It display only Image or only other's info(id,name) individually, But not display together.




--
Anjan Bhowmik
Freelance Software & Web Developer
M : +880 - 1670 - 556419
E : anjan011@gmail.cominfo@ultrasoftbd.com
Site: http://www.onlyfreelancer.com/ - Only for Freelancer's!

__._,_.___
Recent Activity:
Visit phpXperts website at www.phpxperts.net
.

__,_._,___

No comments: