我需要一些关于在 PHP 中创建表的帮助。在我的代码中,我的表格打印了太多次。出于某种原因,代码的输出是任何结果数的计数为 ^2。所以,如果我在实际数据库中有 4 个结果,那么输出中有 16 个结果。我想在论坛发帖之前做更多的研究,但我是 php 新手,不知道从哪里开始。
//Count the number of rows returned
$count = mysql_num_rows($result);
echo $count;
//Table header
echo "<div><table id=\"tableheader\" bgcolor=\"#4382b5\">\n";
echo "<tr>\n";
echo "<td> 3-4 ID:</td>\n";
echo "<td> First Name:</td>\n";
echo "<td> Last Name:</td>\n";
echo "<td> HCA:</td>\n";
echo "<td> File:</td>\n";
echo "<tr>";
echo "</table></div>";
if ($count !== 0) {
while($row = mysql_fetch_array($result)) {
echo "<div class=\"addform\"><form method='get' action=\"update.php\">\n";
echo " <input type=\"text\" value=\"".$row['tfid']."\" name=\"column1\">\n";
echo " <input type=\"text\" name=\"column2\" value=\"".$row['fname']."\"/>\n";
echo " <input type=\"text\" name=\"column3\" value=\"".$row['lname']."\"/>\n";
echo " <input type=\"text\" name=\"column4\" value=\"".$row['hca']."\"/>\n";
echo " <input type=\"text\" name=\"column5\" value=\"".$row['file']."\"/>\n";
echo " <input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n";
echo "<a href=\"delete.php?tfid=".$row['tfid']."\"><img title='Delete Row' alt=\"Delete\" class='del' src='images/delete.png'/></a></form></div>\n";
}
echo "</table><br />\n";
} else {
echo "<b><center>NO DATA</center></b>\n";
}