Answer the question
In order to leave comments, you need to log in
Opencart database query not working. Why?
Need help from Opencarta gurus :) There is a function, the code is below. Can you please tell me why it can not be executed, or an empty result can be returned? The function sometimes produces a result, but it is still not correct. But basically the result is empty. Or tell me how you can see the already formed request that is sent to the database?
protected function getTotalBought($product_id, $order_status_id = 0){
$bought = 0;
$filter_status = " AND o.order_status_id > 0";
if($order_status_id ) {
$filter_status = " AND o.order_status_id IN (".implode(",",$order_status_id).")";
}
$query = $this->db->query("SELECT sum(quantity) as `total` FROM `" . DB_PREFIX . "order_product` op
LEFT JOIN `".DB_PREFIX."order` AS o ON op.order_id = o.order_id WHERE op.product_id = ".$product_id.$filter_status);
if($query->num_rows){
return $query->row['total'];
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
You can see the request that has been formed in the standard way, for example like this
Next, you can check the received request through phpmyadmin and find errors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question