CodeIgniter Forums
DB Select Average - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: DB Select Average (/showthread.php?tid=33520)



DB Select Average - El Forum - 08-29-2010

[eluser]ShoeLace1291[/eluser]
How do I display just the average of the column with the select average function? This is my quuery:

Code:
$this->db->select_avg('price');
$this->db->where('restaurant', $restaurant->id);
$query = $this->db->get('menu_items');



DB Select Average - El Forum - 08-30-2010

[eluser]WanWizard[/eluser]
Code:
$this->db->select_avg('price', 'price');
$this->db->where('restaurant', $restaurant->id);
$query = $this->db->get('menu_items');
$row = $query->row();
echo $row->price;