Reputation: 97
I want to multiply value from table after I selected from database in one column and table using forearch
loops
Here is my selection data from database and I don't know to multiply total value in its column
public function total_comp_in(){
$this->query = $this->db->get_where('prifix',array('status'=>1));
if($this->query->num_rows()>0){
return $this->query->result();
}
}
the result I want to total my value as below images.
Upvotes: 0
Views: 1454
Reputation: 17586
Try this one , you can get the result directly without looping (numbers should be only positive)
SELECT CAST(EXP(SUM(LOG(total))) AS UNSIGNED) AS result
FROM prifix WHERE status = 1
Upvotes: 3
Reputation: 37701
Loop over the results and multiply it:
if($this->query->num_rows()>0){
$total = 1;
$result = $this->query->result();
foreach($result as $row) {
$total *= $row->total;
}
return $total;
}
However, that won't make 2*2*2*2*5 equal 48... maybe if there was a 3 instead of that 5...
Upvotes: 3