PHP mySQL result loop in Table
Page 1 of 1
PHP mySQL result loop in Table
I'm having a problem when trying to display results from mysql db into a table. I am able to dynamically create a new row for each result but cannot nest another loop to add cells to each row. I hope this makes sense. What I would basically like to happen is to query the db and display every website a user has in a new row. Then I would like to query a different table and display each page in the website in a new cell next to the website. Here is my code it should help. <?phpinclude ("connect_to_mysql.php");
mysql_select_db("themenaceman", $con);
?>
<!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>
<h3>Your Account</h3>
<div><?php
$result = mysql_query("SELECT * FROM Websites WHERE userid= '488'");
$result2 = mysql_query("SELECT * FROM pages2 WHERE webname = 'Test Website' AND userid= '488'");
echo "<table border='1'>
<tr>
<th>Website</th>
<th></th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['webname'] . "</td>";
//echo "<td>" while($row = mysql_fetch_array($result2)){ echo $row['pagename'] } "</td>";
echo "<td>" . '<a href="newpage.php?website=' . $row['webname'] .'">Add Page</a>'. "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?></div>
</body>
</html>
Line 28 (commented) is where the problem is (Parse error: syntax error, unexpected T_WHILE, expecting ',' or ';' in /home/content/83/9160783/html/new/account.php on line 28) I hope this is enough information. and thanks in advance for any help.
Re: PHP mySQL result loop in Table
you can not echo a while statementyour code
- Code: Select all
//echo "<td>" while($row = mysql_fetch_array($result2)){ echo $row['pagename'] } "</td>";
correct code
- Code: Select all
echo "<td>";
while($row = mysql_fetch_array($result2)){ echo $row['pagename']; }
echo "</td>";
You are Welcome :)
Page 1 of 1