CodeIgniter Forums

Full Version: DB Select Average
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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');

El Forum

[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;