Edgar Ong Edgar Ong - 4 months ago 8
PHP Question

Return the highest value from model to view

I want to know how to compare these 2 outputs http://prntscr.com/bx7ay9 and return the highest

value
in the
array
?

MY MODEL CODES

$this->db->select('additional');
$this->db->from('order_detail');
$this->db->where('order_id',$id);
$query = $this->db->get();
foreach ($query->result() as $row)
{
$return[] = $row->additional;
}
return $return;

Answer

Just use select_max in query to get highest value and use row() to fetch single row without using foreach loop as

$this->db->select_max('additional AS max_value');
$this->db->from('order_detail');
$this->db->where('order_id', $id);
$query = $this->db->get();
$ret = $query->row();
return $ret->max_value;
Comments