我正在使用 sql 查询从 Mysql db 获取数据。
$query = "select * from User u";
$result = mysqli_query($dbConnect, $query);
while ($row = mysql_fetch_array($result)) {
echo $row['firstName'];
echo $row['lastName'];
echo $row['city'];
echo $row['state'];
echo $row['zipcode'];
echo $row['location'];
echo $row['phoneNumber'];
}
mysqli_close($dbConnect);
?>
上面的代码获取我的数据并将其显示在浏览器中。但是,当我尝试使用此数据创建表时,以下代码会失败:
$query = "select * from User u";
$result = mysqli_query($dbConnect, $query);
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php $row['firstName']?></td>
<td><?php $row['location']?></td>
<td><?php $row['city']?></td>
<td><?php $row['state']?></td>
<td><?php $row['zipcode']?></td>
<td><?php $row['phoneNumber']?></td>
</tr>
<?php
mysqli_close($dbConnect);
}
?>
我收到错误 mysql_fetch_array() 期望参数 1 是资源,在此处选择中给出的布尔值。
更新:(在此处收到 Rockstar 社区成员的意见后)
<?php
include('../include/db_connection.php');
$query = "select * from User u";
$result = mysqli_query($dbConnect, $query);
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row['firstName'];?></td>
<td><?php echo $row['location'];?></td>
<td><?php echo $row['city'];?></td>
<td><?php echo $row['state'];?></td>
<td><?php echo $row['zipcode'];?></td>
<td><?php echo $row['phoneNumber'];?></td>
</tr>
<?php
mysqli_close($dbConnect);
}
?>