Issue
i have this code :
$query = $this->db->get();
$query->row()->price * $colors['quantity'];
$response = $query->row();
return $response;
i'm trying to multiply the price dynamically based on the quantity value, but it does not do nothing, as it returns the row as it is,it doesn't seem logical to me that it does not work, as im multiplying that value before the return, even if i put static value like
$query->row()->price * 2;
still will ignore it
Solution
There is the query builder class to compute the product of price and quantity when selecting it.
You can write:
$this->db->select('price, quantity, price * quantity AS total_amount', FALSE);
$this->db->from('mytable');
$query = $this->db->get();
Answered By - Oluwafemi Sule
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.