Vans Hallden wrote:

Please try to endure my ignorance. I'm new to PHP4 and out to perform just a single isolated task with it. :)

I would like to form some simple statistics from specific column data in a mysql database and display those stats on a webpage.

I have collected a few demographics from certain respondents. These are sex, age, and usage of our service (individual/company). The responses are store in a mysql 3 database.

Basically, I would like to show:

total headcounts and percentages for 'male' and 'female' respondents (database column 'sex')

Here is one way:

$allheads = mysql_num_rows(mysql_query("SELECT sex FROM table"));
$allmales = mysql_num_rows(mysql_query("SELECT sex FROM table WHERE sex = 'male'"));
$allfemales = mysql_num_rows(mysql_query("SELECT sex FROM table WHERE sex = 'female'"));


$avg_male = ($allmales / $allheads) * 100;
$avg_female = ($allfemales / $allheads) * 100;

(probably not the best)

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

usage percentages for male/female respondents (database column 'usage')

What is usage?

I would very much appreciate if someone could point me to eg. code examples helping me to accomplish this task. Unless someone wants to just give away their utmost expertise and send me working code, which would leave me absolutely speechless from respect and gratefulness. =)

Yeah, yeah yeah ... your welcome :P

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



Reply via email to