【发布时间】:2021-06-18 23:14:33
【问题描述】:
这是我的 php 代码无法一次获取多行... 正如我在互联网上看到的,根据 php 的版本,功能是正确的。
<?php
require'db_conn.php';
$q1 = "select * from contact";
$res = mysqli_query($conn,$q1);
echo "
<table class='table'>
<thead class='thead-dark'>
<tr>
<th scope='col'>#</th>
<th scope='col'>id</th>
<th scope='col'>Address</th>
<th scope='col'>City</th>
<th scope='col'>Country</th>
<th scope='col'>State</th>
<th scope='col'>Zip</th>
<th scope='col'>Phone</th>
<th scope='col'>#</th>
</tr>
</thead>";
while ($row = mysqli_fetch_assoc($res))
{
$id = $row["id"];
$address = $row["address"];
$city = $row["city"];
$country = $row["country"];
$state = $row["state"];
$zip = $row["zip"];
$phone = $row["phone"];
}
echo "
<tbody>
<tr>
<td> <input type='checkbox' name=''> </td>
<td>$id</td>
<td>$address</td>
<td>$city</td>
<td>$country</td>
<td>$state</td>
<td>$zip</td>
<td>$phone</td>
</tr>
</tbody>
</table>";
?>
这里的图片包含多行,但是这段代码只是获取单行
【问题讨论】:
-
您的
echo在while循环之外。把它移进去,它应该可以工作