// Populate headers
$fields = $result->fetch_fields();
foreach ($fields as $field)
printf("<th>%s</th>", $field->name);
printf("</tr>");
// Write to table
while ($myvar = $result->fetch_row()) {
$date = $myvar[0];
$room_ID = $myvar[1];
$description = $myvar[2];
$firstname = $myvar[3];
$lastname = $myvar[4];
$message = $myvar[5];
$period = $myvar[6];
printf("<tr>");
printf("<td>%s</td><td>%s</td>", $date, $room_ID);
printf("<td>%s</td><td>%s</td>", $description, $firstname);
printf("<td>%s</td><td>%s</td><td>%s</td>", $lastname, $message, $period);
printf("</tr>");
}
我試圖回顯「沒有結果顯示」,如果我的MySQLi結果返回空。問題是標題是作爲數組的一部分返回的,我該如何實現?如何檢查MySQL結果是否爲空
'num_rows()'會有幫助。 http://php.net/manual/en/mysqli-result.num-rows.php –