RE: [PHP] Average of column...
| From: | Steve Brett | Date: | Tue, 10 Jul 2001 16:01:49 +0000 |
| Subject: | RE: [PHP] Average of column... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-57181@lists.php.net to get a copy of this message | ||
$age_result = mysql_query("select AVG(age) as avgage FROM bat_rost WHERE
ownerID = '$teamID'");
$row = mysql_fetch_row($age_result);
$average_age=$row[0];
echo "Average age of ".$teamID." is ".$average_age;
or
$age_result = mysql_query("select AVG(age) as avgage FROM bat_rost WHERE
ownerID = '$teamID'");
$row = mysql_fetch_array($age_result);
$average_age=$row["avgage"];
echo "Average age of ".$teamID." is ".$average_age;
read the php manual pages on stuff like mysql_fetch_row and
mysql_fetch_array etc.
Steve
> -----Original Message-----
> From: Jeff Lewis [mailto:jeff@hyrum.net]
> Sent: 10 July 2001 16:54
> To: remo.pini@pini.org; php-general@lists.php.net
> Subject: RE: [PHP] Average of column...
>
>
> This doesn't work:
>
> $age_result = mysql_query("select AVG(age) as avgage FROM
> bat_rost WHERE
> ownerID = '$teamID'");
> $row = mysql_fetch_object($age_result);
> $age=$avgage;
> echo "Average age - ".$teamID.$avgage;
>
> Neither does this:
>
> $age_result = mysql_query("select AVG(age) as avgage FROM
> bat_rost WHERE
> ownerID = '$teamID'");
> $res = mysql_fetch_row($age_result)
> $age=$res[0];
> echo "Average age - ".$teamID.$avgage;
>
>
> > -----Original Message-----
> > From: Remo Pini [mailto:remo.pini@pini.org]
> > Sent: Tuesday, July 10, 2001 11:41 AM
> > To: jeff@hyrum.net; php-general@lists.php.net
> > Subject: RE: [PHP] Average of column...
> >
> >
> > if you do a
> >
> > $res = mysql_fetch_row($age_result)
> >
> > $res[0] will be the value of AVG(age).
> >
> >
> > > -----Original Message-----
> > > From: Jeff Lewis [mailto:jeff@hyrum.net]
> > > Sent: Tuesday, July 10, 2001 5:27 PM
> > > To: php-general@lists.php.net
> > > Subject: [PHP] Average of column...
> > >
> > >
> > > I am trying to obtain the average age for a few teams in
> my database.
> > >
> > > Am using the below code:
> > >
> > > $age_result = mysql_query("select AVG(age) FROM bat_rost
> WHERE ownerID =
> > > '$teamID'");
> > > while(($row = mysql_fetch_object($age_result))){
> > > $age=$row->age;
> > > echo "Average age - ".$teamID.$age;}
> > >
> > > How can I get the average age from this?
> > >
> > > Jeff
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-general-help@lists.php.net
> > > To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
> > >
> > >
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>