Reputation: 9037
I have this code
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("juliver", $con);
$result = mysql_query("SELECT * FROM menu");
$sm = "";
while($row = mysql_fetch_array($result))
{
$sm .= "<li><a href='#".$row['page'].'">'.$row['menulist']."</a></li>";
}
mysql_close($con);
?>
<? echo $sm; ?>
My database is look like this.
id menulist page
1 Home tb1
2 Gallery tb2
3 Clothing tb3
4 Furniture tb4
5 Household-items tb5
the output should be this if converted into html.
<li><a href="#tb1">Home</a></li>
<li><a href="#tb2">Gallery</a></li>
<li><a href="#tb3">Clothing</a></li>
<li><a href="#tb4">Furniture</a></li>
<li><a href="#tb5">Household-items</a></li>
I tried removing, adding, renaming and etc into the code and etc. but im still stuck and none of them work.
please help me.
Upvotes: 0
Views: 67
Reputation: 12973
Your quotes seem to be muddled up. Your literal text should be enclosed in double quotes (since they appear first), and everything else use single quotes:
$sm .= "<li><a href='#".$row['page']."'>".$row['menulist']."</a></li>";
results in
$sm .= "<li><a href='#tb1'>Home</a></li>";
which you can then output.
You might want to add a \n
in there as well, to format the output nicely.
$sm .= "<li><a href='#".$row['page']."'>".$row['menulist']."</a></li>\n";
Upvotes: 1