// 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 –