【发布时间】:2013-05-13 02:35:26
【问题描述】:
我有一个简单的问题。我有下面的 while 语句正在工作,但正在两次打印表中的所有内容。我是 PHP 和 MySQL 的新手,不知道为什么。有人可以帮我指出正确的方向吗?
while($row = mysql_fetch_array($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
$linkID= $row['linkID'];
echo '<td><a href="update.php?linkID=' . $linkID. '">Update Status</a></td>';
echo "</tr>\n";
}
【问题讨论】:
-
你在一段时间内使用 foreach
-
mysql_*函数不再支持,它们是 officially deprecated,不再维护,将在未来。您应该使用PDO 或MySQLi 更新您的代码,以确保您的项目在未来的功能。 -
除非已知数据是 html 安全的,否则您应该使用
htmlspecialchars转义$cell。
标签: php mysql while-loop html-table