0

I encountered a problem in writing PHP code. This is the error:

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

And this is my PHP code:

if(!empty($_GET['KEY'])){
    $CAT=$_GET['CAT'];
    $KEY=$_GET['KEY'];

    $content = mysqli_query($con,"SELECT * FROM model WHERE cat1 ='$CAT' UNION
                                SELECT * FROM model WHERE cat2 ='$CAT' UNION
                                SELECT * FROM model WHERE cat3 ='$CAT' UNION
                                SELECT * FROM model WHERE keyword1 ='$KEY' UNION
                                SELECT * FROM model WHERE keyword2 ='$KEY' UNION
                                SELECT * FROM model WHERE keyword3 ='$KEY' UNION
                                SELECT * FROM model WHERE keyword4 ='$KEY' UNION
                                SELECT * FROM model WHERE keyword5 ='$KEY' 
                                ORDER BY rate DESC;");

    }else {
$CAT=$_GET['CAT'];
$content = mysqli_query($con,"SELECT * FROM model WHERE cat1 ='$CAT' UNION
                            SELECT * FROM model WHERE cat2 ='$CAT' UNION
                            SELECT * FROM model WHERE cat3 ='$CAT' 
                            ORDER BY rate DESC;");
}

    $output = array();
while($row = mysqli_fetch_array($content)){
     $record = array();
     $record['rate'] = $row['rate'];
     $output[] = $record;

}

of Course I admit I am beginner in PHP And Hope you help me thanks to everyone.

Haj Ali
  • 93
  • 2
  • 11
  • 1
    Possible duplicate of [mysql\_fetch\_array()/mysql\_fetch\_assoc()/mysql\_fetch\_row()/mysql\_num\_rows etc... expects parameter 1 to be resource](https://stackoverflow.com/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-mysql-num-rows-etc) – tkausl Feb 11 '18 at 12:12

1 Answers1

1

This indicates that, SQL does not return any record. You $content variable is empty.

if (!empty($content)) {
 while($row = mysqli_fetch_array($content)){
     $record = array();
     $record['rate'] = $row['rate'];
     $output[] = $record;
 }
}

This will help you

Lalit Mohan
  • 464
  • 3
  • 16