我有一些麻烦,我的第一个PHP项目,我试图从MySQL数据库(有3条记录)获取数据并将其显示在表中。问题是它似乎只显示记录2和3,它跳过第一条记录。请参阅我的代码并在下面显示。在表中显示记录
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM unitstats");
while($row = mysqli_fetch_array($result)) {
echo "<table border='1' style='color:white'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
什么是第一个'while'在做什么? – Salman
'while($ row = mysqli_fetch_array($ result))'我不认为你知道这是什么T.T – hanzo2001
为什么所有的答案都被低估? – user2936213