CodeIgniter Forums
DB Select Average - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: DB Select Average (/thread-33520.html)



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;