0

I'm new to PHP (just teaching myself) and have the following error in PHP but I cant get my head arround the problem:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in

 <!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>
Paulie-C
  • 1,514
  • 1
  • 11
  • 28
Ron Long
  • 11
  • 4
  • Check here https://stackoverflow.com/a/15440076/4511459 – Nawin Jun 30 '17 at 05:14
  • 2
    there may be query error. use mysqli_error() function to know error. $result = mysqli_query($connx, $sql_query) or die(mysqli_error($connx)); – Akshay H Jun 30 '17 at 05:15

2 Answers2

-1

Please use only one parameter in this function.

 while($row = mysqli_fetch_array($result)) {
    ....
  }
Bhavin Thummar
  • 1,120
  • 1
  • 11
  • 23
-2

please use the below query

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;

and

while($row = mysqli_fetch_array($result)) {
   ....
  }
Mani Singh
  • 103
  • 1
  • 2
  • 14