This question already has an answer here:
I am getting data from Mysql db using a sql query.
$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);
?>
The above code gets me data and displays it in the browser. However when i try to create a table using this data it fails for the following code:
$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);
}
?>
I am getting error mysql_fetch_array() expects parameter 1 to be resource, boolean given in select here.
Update: (After inputs from Rockstar community members here)
<?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);
}
?>
</div>
correct your fetch code
while ($row = mysql_fetch_array($result)) {
to
while ($row = mysqli_fetch_array($result)) {
either use mysql or mysqli, I feel you should preferred mysqli. Don't mix both of them.
i think you are usingmysqli_close($dbConnect);
insidewhile
This may cause...to stop fetching the data