-1

I am facing this issue while executing my script. I am trying to execute a query, but it is showing me this error "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given". Please find below script. I am using SugarCRM framework.

$query4 = $reportquery;
var_dump($query4);
$value4 = $db->query($query4);
var_dump($value4);
while($row = $value4->fetch_assoc()){
    print_r($row);
}

$query4 is a string, but when I dump $value4, it gives me bool(false) result. When I dump $query4, it gives me this

string(292) "SELECT opportunities.amount AS 'Opportunity Amount',opportunities.probability AS 'Probability (%)',opportunities.name AS 'Opportunity Name', COUNT(*) AS 'TOTAL' FROM opportunities WHERE opportunities.deleted = 0 GROUP BY opportunities.amount LIMIT 0,15"

When I execute this query as it is in db directly, it works. But here it is giving me an error. Kindly guide me here.

Changez Khan
  • 49
  • 1
  • 8

1 Answers1

-1

Do Error-Handling

$query4 = $reportquery;
var_dump($query4);
$value4 = $db->query($query4);
//if $value4 is false, there went something wrong with the query
if(!$value4){
     echo $db->error; //Will give you the last error that appeared
}else{
    while($row = $value4->fetch_assoc()){
        print_r($row);
    }
}

Evaluate the error to see where you have to make adjustments

Tanuel Mategi
  • 1,251
  • 6
  • 13