Re: Re: How to call image from mySql to php file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$query = mysql_query("SELECT logos FROM table WHERE sno = '$sno' limit 1") or die(mysql_error());

while ($result = mysql_fetch_array($query)) {
   $sno = $result[logos];
}

?>

<img src="<?php echo($sno); ?>"></img>

hope it helps....
----- Original Message ----- From: "Fahad Pervaiz" <fahad.pervaiz@xxxxxxxxx>
To: <chandan9sharma@xxxxxxxxx>; <php-general@xxxxxxxxxxxxx>
Sent: Friday, February 23, 2007 9:38 PM
Subject:  Re: How to call image from mySql to php file


#####ORIGINAL#####
I have a field in database called "logos" which has one value
"images/logos/some_logo.jpg"

In my php I am trying to call it in my php file as image. With this code.

$sno = $_REQUEST['sno'];

$query="SELECT logos FROM table WHERE sno = '$sno'";

$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();
$logos=mysql_result($result,$i,"logos");

echo "
<div>
<p> $logos </p>
</div>";

?></div>

But getting errors. What is the way to call image in php file from the
database. I know that this is a very basic question but first time for me. I

ignored this in the begining but now its right infront of me.

Please advice.
#####END ORIGINAL#####

There are two ways to store images in databases.

First is that you upload your images to a directory and store path to that
image in the database. In this case make sure that your field size is large
enough to store the complete path. You can use the following code to
retreive the image and display it.

$sno = $_REQUEST['sno'];

$query="SELECT logos FROM table WHERE sno = '$sno' limit 1";

$result=mysql_query($query);
$num=mysql_numrows($result);

if ( ! $result )
       die("Unable to get records");

    while($row= mysql_fetch_array( $result ))
{
        $image= $row["sno"];
    }

mysql_close();

echo "
<div>
<img src='$logos' border='0'>
</div>";


The second method is a bit complicated. You store images in a binary field
of database and when you retrieve the image, you retrieve it via proxy file
e.g. image.php
the image.php outputs the image using header

<?
header('Content-type: image/jpeg');

$sno = $_REQUEST['sno'];

$query="SELECT logos FROM table WHERE sno = '$sno' limit 1";

$result=mysql_query($query);
$num=mysql_numrows($result);

if ( ! $result )
       die("Unable to get records");

    while($row= mysql_fetch_array( $result ))
{
        $image= $row["sno"];
    }

mysql_close();

echo $logos;

?>

you can make call to it from you abc.html as follows
<div>
<img src="image.php?sno=<?=$_REQUEST['sno']?>" />
</div>

--
Regards
Fahad Pervaiz
www.ecommerce-xperts.com
(Shopping Carts, Framwork for
Multilingual Web Sites, Web Designs)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux