我的代码有什么问题?我的目的是创建一个表格,将行输入到具有可变行数的 html 表格中。我的代码返回警告:
为 foreach() 提供的参数无效
<?php
{
$user=$_SESSION['username'];
$pass=$_SESSION['password'];
}
$con = mysql_connect("localhost","****","*****");
var_dump($con);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****", $con);
$result = mysql_query("select * from `order` WHERE username='$user'");
while ($row = mysql_fetch_array($result))
{
$html_table = '<table border="1 cellspacing="0" cellpadding="2""><th>Company Symbol </th><th>Amount </th><th>Actual Stockprice </th><th>Old Stockprice </th><th>Cost </th><th>Profit/loss </th><tr>';
foreach($result as $row) {
$html_table .= '<tr><td>' .$row['company']. '</td><td>' .$row['amount']. '</td><td>' .$row['stock']. '</td></tr>';
}
$html_table .= '</tr></table>';
$html_table = str_replace('<tr></tr>', '', $html_table);
echo $html_table;
}
?>
任何帮助都会很棒。