Forum Moderators: coopster

Message Too Old, No Replies

Problem viewing picture from database using php but with html

         

dewteks

12:46 pm on Sep 6, 2007 (gmt 0)

10+ Year Member



I have a table which i intend to display its contents including pictures through php.

if i try retrieving only the picture field with the code below in an html file it works

<img src="ame2.php?pid=<?php echo $pid ='6'?>">

the file "ame2.php" uses pid identify row to display and in this case pid=6.

but does not work with the php script below. what am i getting wrong, what should i do,Pls help!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("gozmok", $con);

$result = mysql_query("select albumid, album_title, total_tracks, duration, media_category, price from albums");

echo "<table width='90%' border='1' cellpadding='0'>

<tr>
<th></th>
<th></th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo ('<tr>');
$pid=$row['albumid'];
$image ='<br><img src="ame2.php?pid=$pid">';

echo ('<td ><b>'."Title: ".$row['album_title'] .$image ." <br>Price: ". $row['price'] . '</b></td>');
echo ('<td>'."No of Tracks: ". $row['total_tracks'] ."<br>Media Type: ". $row['media_category'] ."<br> Play Time: ". $row['duration'] . '<br><a href="albumdetails.php?id=.$pid">More</a>'.'</td>');
echo ("</tr>");
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>

pls any assistance will be appreciated.

omoutop

1:50 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try this :

$image ="<br><img src=\"ame2.php?pid=".$pid."\">";

in your code you must escape the double quotes (")

dreamcatcher

3:03 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don`t need to escape double quotes if your string is between apostrophes, however you do need to enclose your var in quotes if its not between double quotes. PHP will only parse a var if its not quoted when between double quotes.

Hope that makes sense.

echo "$var"; // ok
echo '$var'; //not ok

Should be:

$image ='<br><img src="ame2.php?pid='.$pid.'">';

dc

dewteks

3:05 pm on Sep 10, 2007 (gmt 0)

10+ Year Member



thank bro.
both options worked.