我正在尝试遍历mysql表并显示属性。由于某种原因,它只显示一行数据。我做错了什么?
$query = "SELECT DATE(date) AS date, type, time_in_minutes, heartrate, calories FROM exercise_log WHERE id = '" . $_SESSION['id'] . "'";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
while ($row = mysqli_fetch_array($result)) {
echo $row['date'] . $row['type'] . $row['time_in_minutes'] .
$row['heartrate'] . $row['calories'] .
'<ahref="removelog.php"><img id="trash" src="images/trashcan.png" alt="Profile Picture"></a><hr/><br />';
}
mysqli_close($dbc);
答案 0 :(得分:0)
使用下面的代码检查结果集的计数
$query = "SELECT DATE(date) AS date, type, time_in_minutes, heartrate, calories FROM exercise_log WHERE id = '" . $_SESSION['id'] . "'";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
while ($row = mysqli_fetch_array($result)) {
echo $row['date'] . $row['type'] . $row['time_in_minutes'] .
$row['heartrate'] . $row['calories'] .
'<ahref="removelog.php"><img id="trash" src="images/trashcan.png" alt="Profile Picture"></a><hr/><br />';
}
mysqli_close($dbc)
;
这将显示您的查询提取的记录数