gpt4 book ai didi

php - while 循环仅显示数据库中的第一行

转载 作者:行者123 更新时间:2023-11-29 16:02:31 25 4
gpt4 key购买 nike

我知道这是一个非常基本的问题,但我一整天都找不到答案。我试图在表中显示所有数据库行,而我的 while 循环仅显示第一行。

我尝试将 while 循环的条件更改为“mysqli_fetch_array”,然后甚至没有显示第一行。

echo "<table>";
echo "<tr>
<th>Match_Id</th>
<th>Home_Team</th>
<th>Away_Team</th>
<th>Result</th>
<th>season</th>
<th>notes</th>
<th>Goals_Sum</th>
</tr> ";


$sql = "SELECT * FROM PremierLeague";
`enter code here` $result = sqlsrv_query($conn, $sql);

while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
echo "<tr>";
$id = $row['id'];
echo "<td>$id</td>";
$Home = $row['Home'];
echo "<td>$Home</td>";
$Away = $row['Away'];
echo "<td>$Away</td>";
$result = $row['result'];
echo "<td>$result</td>";
$season = $row['season'];
echo "<td>$season</td>";
$notes = $row['notes'];
echo "<td>$notes</td>";
$home_goals= $row['home_goals'];
$away_goals= $row['away_goals'];
$GoalSum = $home_goals+$away_goals;
echo "<td>$GoalSum</td>";
echo "</tr>";
}
echo "</table>";

预期结果:包含数据库中所有行的表。实际结果:仅数据库中的第一行

最佳答案

echo "<table>";
echo "<tr>
<th>Match_Id</th>
<th>Home_Team</th>
<th>Away_Team</th>
<th>Result</th>
<th>season</th>
<th>notes</th>
<th>Goals_Sum</th>
</tr> ";


$sql = "SELECT * FROM PremierLeague";
$result = sqlsrv_query($conn, $sql);

while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$id = $row['id'];
$Home = $row['Home'];
$Away = $row['Away'];
$result = $row['result'];
$season = $row['season'];
$notes = $row['notes'];
$home_goals= $row['home_goals'];
$away_goals= $row['away_goals'];
$GoalSum = $home_goals+$away_goals;



echo $output.="<tr>
<td>$id</td>
<td>$Home</td>
<td>$Away</td>
<td>$result</td>
<td>$season</td>
<td>$notes</td>
<td>$GoalSum</td>
</tr>";
}
echo "</table>";

关于php - while 循环仅显示数据库中的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56064812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com