Log in

View Full Version : display image from database with links



binukjames
06-26-2008, 11:18 AM
I'm developing a wap site using wml and php.
my php code is retrievig and displaying blob image from database.
but i cannot include any wml part to this page.
actually i want to display image from database with some links.
is it possible ?give me any sample code... plz help me....

my code is.......


<?php
function db_connect($user='root', $password='admin', $db='example')
{
mysql_connect('localhost', $user, $password) or die('I cannot connect to db: ' . mysql_error());
mysql_select_db('example');
}
// echo "hellow world";
db_connect();
$sql = "select imgdata from pix where title=1";
$result = mysql_query("$sql");
while($row = mysql_fetch_array($result))
{
$bytes = $row['imgdata'];
}
header("Content-type: image/jpeg");
print $bytes;

exit ();
mysql_close();
?>


--------------------------------------------------------------------------

OUTPUT : DISPLAYING IMAGE
--------------------------------------------------------------------------

BUT IF I REMOVE COMMENT FOR echo "hellow world"; THE OUTPUT WILL B LIKE THIS

-------------------------------------------------------------------------

hellow world

Warning: Cannot modify header information - headers already sent by
(output started at C:\web\htdocs\show\image.php:7) in C:\web\htdocs\show\image.php on line 15

ÿØÿàJFIF``ÿá ExifMM*bj(1r2އi¤Ð¦'
H¼—«ÿ?îÛ„ætºDûiÇ?cùÛòÿæöý:+¡tÿ㇦fäâàg³
\,3cr]¸Cq¥”XæÍs‡¥½y?8"¼ŠÝ‘Sí ¶¶;Ó{›ûµØæX
Ö_b»ÊáÇ(ÈqK÷ul?ΦWÖÿ¯ »ì¹K.»Ûþ è;_st?ß¹Cþ
}}s«ôNê™ ö?í¥ÀŽÏÞÍû¿¬»^…õ÷¢tþ†jvŒê-ž—M¦û
öÜÇ?»*Íôªô½;ôôú¡Æôý/WùµV¼ÿñ]Ôžoê}2ì<ÜÇ9ÙV9×=

•Úùu–}¢«6mßþÑÿ±=Ĺ}"kÒ?«»þ+:ÿXëXÎê™NÊv=¬eNsZk

š\Ặ³»÷×rõOêÿB蘹tL‡dbæ<[½Ö6Ö ¢éYPú]ùë3ëøÆ¯
¤õ+:nêc†œ§›EU³{[§†\ë\æ»ôžÖzj©?¹’^Üt&Àð]°ÕíS@XÿVz
ïí®??Ô.kqîÈu£ìáû‹EvÛC¬=îÙW»Ú´îÊÇ }¬¨;F—¸6cÃqQ?A ?B
S$¨³ô{æWŸŒ÷3W5·VHÊÕ²ö
¸˜2x?ILÒUêÎùÛ)¾»\âö¸ÇïCJ][¥Ý?1©Ì¢Ì‡[K ....

Jas
06-26-2008, 07:05 PM
To display an image, you can only output the image. You cannot output anything else before of after the image. The way to put the image in a page is like this:


<img src="./image_script.php" />

The image tag opens the PHP script and displays the image for you. Example:


<?php
echo <<<END;
<html>
<head>
<title>image</title>
</head>
<body>
<p>Below is an image</p>
<img src="./image_script.php" />
</body>
<html>
END;
?>
(where image_script.php is the PHP script that produces the image)