Hello. This is my first post in PHP Theory and Design, and I'm posting here not because I have a syntax question, but because I have a theory question. I'm making demographics of memebers on my site. I have a table that contains all the info I'd need to for the demographics, but I pull one demographic at a time with my function. For example, the function can only create data for age on one run. I want it to output something like "15% of the users are 20, 2% are 21, 40% are 30..etc" if the demographic in question is age. I have started coding this, and got this:
Code: Select all
<?php
/**
@param string $demographic
@returns
@desc Demographics for the site. Parameter options are "age", "sex", and "country".
Sample return for age: 15% are 16 years old, 10% are 20 years old, etc...
*/
function demographics ($demographic){
$users = sql_pull("SELECT `$demographic` FROM `users`", $db);
for ($i=0, $finish=sizeof($users);$i<$finish;$i++){
//then i get confused...
}
}
?>
A not on sql_pull(): it performs the MySQL query, and returns the result in a 2D array, through which I can cycle using a for loop.
Okay, I know I need the amount of people of a certain characteristic (i.e. of one age), and I need the total users. I have the total users, (sizeof($users), I'm just uinsure how to get the amount of users of a certain characteristic. Ideas?
Thanks!
