March 27, 2012
displaying all records in separate div
Question by user1292042
Ok. I have this code.
$result = mysql_query("SELECT * FROM items");
while($row = mysql_fetch_array($result))
{
$ss = "<div>";
$ss. = '<img src="'.$row['name'].'" />';
$ss. = $row['title'];
$ss. = $row['description'];
$ss. = $row['link'];
$ss. = "</div>";
}
My HTML is like this
<html>
<head>
<style type="text/css">
body{background:gray;}
div{border:1px solid red;}
</style>
</head>
<body>
<? echo $ss; ?>
</body>
</html>
But I get an error
Parse error: syntax error, unexpected ‘=’ in … on line 83
I just want to display all records with separate div.
Answer by Starx
Problem is on this line
$ss. = '<img src="'.$row['name'].'" />'; // ^ See the . with the space in between, it should be .=
Continue fixing all the line like that.
Solution:
$ss = "";
while($row = mysql_fetch_array($result))
{
$ss .= "<div>";
$ss .= '<img src="'.$row['name'].'" />';
$ss .= $row['title'];
$ss .= $row['description'];
$ss .= $row['link'];
$ss .= "</div>";
}