Welcome Guest, Not a member yet? Register   Sign In
Displaying Average
#1

[eluser]PHP Creative[/eluser]
Very, very basic question I apologise. How do you display the AVG from a query as a variable? For example

Code:
$this->db->select_avg('age');
$query = $this->db->get('users');

Thanks a million.
#2

[eluser]jedd[/eluser]
Code:
$this->db->select_avg('age');
$query = $this->db->get('users');

if ($query->num_rows() > 0)   {
   $row = $query->row();
   $average = $row->avg;
   }

If you're on PHP5 you can chain the query->row()->avg I believe. (Don't quote me - I don't use AR calls)
#3

[eluser]Dam1an[/eluser]
There's a handy second paramter (it's in the user guide)

Quote: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.




Theme © iAndrew 2016 - Forum software by © MyBB