Could anyone tell me how to adapt or change this code to print multiple rows from a database table into an html table using PHP? Every user will have a different number of records in the table so I will need to use some kind of loop to print out the rows.
<?php
include_once 'dbconfig.php';
$statement = $db_con->prepare("SELECT * FROM entry WHERE user_id=:uid");
$statement->execute(array(":uid"=>$_SESSION['user_session']));
$result=$statement->fetch(PDO::FETCH_ASSOC);
?>
<table>
<tr>
<th>Entry</th>
<th>Date</th>
<th>Weight</th>
<th>BMI</th>
<th>Calories Consumed</th>
<th>Calories Burned</th>
<th>Calorific Deficit</th>
</tr>
<?php
while($row = mysql_fetch_array($result)) {
$entry = $row["entry_id"];
$date = $row["date"];
$weight = $row["weight"];
$bmi = $row["bmi"];
$consumed = $row["calories_consumed"];
$burned = $row["calories_burned"];
$deficit = $row["calorie_deficit"];
echo "<tr>
<td>$entry</td>
<td>$date</td>
<td>$weight</td>
<td>$bmi</td>
<td>$consumed</td>
<td>$burned</td>
<td>$deficit</td>
</tr>";
}
?>
</table>
This currently works fine but it only prints out the first row relevant to the particular user rather than looping through and printing a row for each record.
Updated to include while loop