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>";

}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!