Home > Mobile >  multiplying a value in a row dynamically before returning it
multiplying a value in a row dynamically before returning it

Time:09-17

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

CodePudding user response:

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();
  • Related