"Vans Hallden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> >Here is one way:
> >(probably not the best)
>
> I was able to get almost everything working with your help. Thanks!!! :)
>
> >>average ages for male/female respondents (database column 'age')
> >
> >SELECT AVG(age) FROM tablename WHERE sex = 'male';
> >SELECT AVG(age) FROM tablename WHERE sex = 'female';
>
> I have one small problem remaining. With this code:
>
> $male_average_age = mysql_query("SELECT AVG(age) FROM my_database
> WHERE sex = 'M'");
>
> ..I get a strange "Resource id#10" output. I can't figure out why.
> What am I missing?

mysql_query() is returning a result resource handle. You have to use
mysql_fetch_row or a similar function to access the result set:

$result = mysql_query("SELECT AVG(age) as avgAge FROM my_database WHERE sex
= 'M'");

// get the first row of the result as an associative array
$row = mysql_fetch_assoc($result);
$male_average_age = $row['avgAge'];

Take a look here:
http://de2.php.net/manual/en/function.mysql-fetch-assoc.php

Regards, Torsten

> --
>
> --
> Hans Vallden
> [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to