Jump to content

Archived

This topic is now archived and is closed to further replies.

checkmodem12

how to display picture from database

Recommended Posts

this is the code that shows the URL link of the picture that is in my database. is there a way to display so the picture appears and not just the link?




<?
$username="";
$password="";
$database="";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM test_mysql WHERE classification='crafts'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$description=mysql_result($result,$i,"description");
$price=mysql_result($result,$i,"price");
$picture=mysql_result($result,$i,"picture");
$classification=mysql_result($result,$i,"classification");
?>

<table width="100%">
<tr><font face="Arial, Helvetica, sans-serif" size="2">Name:<? echo $id; ?></font></tr>
<tr><font face="Arial, Helvetica, sans-serif" size="2">Description: <? echo $description; ?></font></tr>
<tr><font face="Arial, Helvetica, sans-serif" size="2">Price: <? echo $price; ?></font></tr>
<tr><font face="Arial, Helvetica, sans-serif" size="2">Picture: <a href="<? echo $picture; ?>"><? echo $picture; ?></a></font></tr>
<tr><font face="Arial, Helvetica, sans-serif" size="2">Class: <? echo $classification; ?></font><br><br></tr>



<?
$i++;
}





?>
   

Share this post


Link to post
Share on other sites
First, using mysql_result is bad -- mysql_fetch_assoc() is better.  Second, I assume the picture column is a blob?  If so, you need to have a different PHP serve it.

Share this post


Link to post
Share on other sites
Change
[code]<tr><font face="Arial, Helvetica, sans-serif" size="2">Picture: <a href="<? echo $picture; ?>">
<? echo $picture; ?>[/url]</font></tr>[/code]

to

[code]<tr><td><font face="Arial, Helvetica, sans-serif" size="2">Picture:</font> <a href="<? echo $picture; ?>">
<img src="<? echo $picture; ?>"></a></td></tr>[/code]

You are also missing a few <td>..</td> tags

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.