Jump to content


Photo

how to display picture from database


  • Please log in to reply
2 replies to this topic

#1 checkmodem12

checkmodem12
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 14 July 2006 - 03:53 AM

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++;
}





?>
   

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 July 2006 - 05:27 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 14 July 2006 - 11:46 PM

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

to

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

You are also missing a few <td>..</td> tags
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users