How to get Average value in MySQL table column using Codeigniter
Codeigniter provides the select_avg method to get the average value in the MySQL table column. Writes a “SELECT AVG(field)” portion for your query. As with select_max(), You can optionally include a second parameter to rename the resulting field.
Let’s create a select_avg method in codeigniter
$this->db->select_avg('amount');
$result = $this->db->get('tbl_product')->row();
return $result->amount;
Leave a Reply