Hi, i need help for following issues: 1 How to display total number of members from by database in php file.. please post a php code 2 How to display total number of male and female members from my database. please post a php code i have a database where std_user is username std_gender is for gender thanx
I didn't try, but it would become something like this: $query_total = mysql_query("SELECT count(1) FROM users") or die(mysql_error()); $total = mysql_result($query_total,0); $query_male = mysql_query("SELECT count(1) FROM users WHERE std_gender = 'male'") or die(mysql_error()); $male = mysql_result($query_total,0); $female = $total - $male; echo "Total: ". $total ."<br /> Male: ". $male ."<br /> Female: ". $female .""; PHP: Good luck.
This code works technically, but I'd like to just make a small note: $female = $total - $male; The above line of code counts the total number of females, however, I would prefer to actually get the count from the database: $query_female = mysql_query("SELECT count(1) FROM users WHERE std_gender = 'female'") or die(mysql_error()); $female = mysql_result($query_female,0); The reason I say this is because if there are some records in the database where the gender have not been assigned then using the arithmetic above will give you a higher female count than what actually exists. You should probably then also include: $query_unknown = mysql_query("SELECT count(1) FROM users WHERE std_gender not in ('male', 'female')") or die(mysql_error()); $unknown = mysql_result($query_unknown,0); Just a personal preference... PS, kleinnico, where are you from? Your name means little nico in Afrikaans?
If you indeed don't force the user to enter the right gender then you might get that problem yep. Offtopic: Hhehe I'm from the Netherlands. In Dutch it also means little nico (as Dutch and Afrikaans looks a little bit similar) Actually I've been always pretty big and my last name is also big in Dutch. So thats why I've chosen that nickname some years ago hehe