我是PHP的新手(只是自学)并且在PHP中出现以下错误但是我无法解决问题:
警告:mysqli_fetch_array()要求参数1为mysqli_result,布尔值在
中给出
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head
content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Fredos Bar & Grill | Rated meals report</title>
<!-- Custom styles for this template -->
<link href="css/sticky-footer-navbar.css" rel="stylesheet">
<link href="css/custom4.css" rel="stylesheet">
<link href="css/jumbotron.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and
media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js">
</script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js">
</script>
<![endif]-->
</head>
<body>
<?PHP
include '../includes/fredos-header.php';
include '../includes/fredos-db-connect.php';
$sql_query = "select f.cafeid, f.MenuItemID, title, MenuItemDesc, Price,
MenuItemPhoto, format(avg(f.RatingScore),2) as 'rating'
from menuitems m inner join feedback f on m.MenuItemID = f.MenuItemID
where f.CafeID = 1
group by f.CafeID, f.MenuItemID;";
$result = mysqli_query($connx, $sql_query);
//include '../includes/fredos-menu.php';
function Get_Rating_Colour($Rating_In) {
$final_result = "";
if ($Rating_In >= 3.75) {
$final_result = "rating-bg rating-bg-darkgreen white";
} elseif ($Rating_In >= 3.00){
$final_result = "rating-bg rating-bg-yellowgreen white";
} elseif ($Rating_In >= 2.00){
$final_result = "rating-bg rating-bg-yellow white";
} elseif ($Rating_In >= 1.00){
$final_result = "rating-bg rating-bg-red white";
} else {
$final_result = "rating-bg rating-bg-orange white";
}
return $final_result;
}
?>
<!-- Begin page content -->
<div class="container-fluid">
<h1 class="page-header" class="text-center">All rated menu items</h1>
<div class="row">
<div class="col-lg-12">
<table class="table table-striped">
<?php
$number_meals = 1;
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
$meal_title = $row['title'];
$meal_desc = $row['MenuItemDesc'];
$meal_price = $row['Price'];
$meal_photo = $row['MenuItemPhoto'];
$meal_rating = $row['rating'];
?>
<tr>
<td><img
class="square-image" src="images/meals/<?= $meal_photo ?>" alt="staff menu
item" /></td>
<td><h4><?=
$meal_title ?></h4><?= $meal_desc ?><br />$<?= $meal_price ?></td>
<td><h4 class="<?=
Get_Rating_Colour($meal_rating) ?>"><?= $meal_rating ?></h4></td>
<!-- td><a
class="btn btn-default" href="rated-menu-items-var.html" role="button">Other
variations</a></td -->
</tr>
<?PHP
$number_meals++;
}
?>
</table>
</div>
</div>
</div>
<?PHP
include '../includes/fredos-footer.php';
?>
</body>
</html>
答案 0 :(得分:-1)
请在此功能中仅使用一个参数。
while($row = mysqli_fetch_array($result)) {
....
}
答案 1 :(得分:-2)
请使用以下查询
select f.cafeid, f.MenuItemID, m.title, m.MenuItemDesc, m.Price,
m.MenuItemPhoto, format(avg(f.RatingScore),2) as 'rating'
from menuitems m inner join feedback f on m.MenuItemID = f.MenuItemID
where f.CafeID = 1
group by f.CafeID, f.MenuItemID;
和
while($row = mysqli_fetch_array($result)) {
....
}