Display images in looping table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yeo_yeo2000
Forum Newbie
Posts: 6
Joined: Fri Oct 22, 2004 9:26 am

Display images in looping table

Post by yeo_yeo2000 »

I am trying to show an image in a looping table. I would like to display the image connected with each ID in a field on my table. Here is my code
while($row= mysql_fetch_array($result))
{
$list .= "<tr>";
$list .= "<td>".$row["year"]."</td>";
$list .= "<td>".$row["Make"]."</td>";
$list .= "<td>".$row["spec"]."</td>";
$list .= "<td>".$row["miles"]."</td>";
$list .= "<td>".$row["price"]."</td>";
$list .= "<td>".$row["<img src="getdata.php3?id=$row["id"]"]."</td>";
$list .= "</tr>";
}
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

$list .= "<td><img src="getdata.php3?id=".$row["id"]."</td>";
yeo_yeo2000
Forum Newbie
Posts: 6
Joined: Fri Oct 22, 2004 9:26 am

Post by yeo_yeo2000 »

I tried that but I keep getting a parse error on that line?
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

whats the error?
yeo_yeo2000
Forum Newbie
Posts: 6
Joined: Fri Oct 22, 2004 9:26 am

Post by yeo_yeo2000 »

Parse error: parse error in /usr/local/psa/home/vhosts/yomac.net/httpdocs/test.php on line 31

I also tried
$list .= "<td><img src="getdata.php3?id=".$row["id"].""></td>";
But get the same error
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

Code: Select all

$list .= "<td><img src='getdata.php3?id=".$row['id']."'</td>";
More use of single quotes inside the string...
yeo_yeo2000
Forum Newbie
Posts: 6
Joined: Fri Oct 22, 2004 9:26 am

Post by yeo_yeo2000 »

Thats it thanks I can stop pulling my hair out now
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

you could also have done

Code: Select all

<?php
$list .= "<td><img src="getdata.php3?id="".$row['id'].""></td>";
?>
by escaping the quotes that need to be there for the img src
Post Reply