Just wondering if someone would help me out with this block,
I know the SQL would be something like this....
Total Males
SELECT count( gender )
FROM _members
WHERE gender =1
Total Females
SELECT count( gender )
FROM _members
WHERE gender =2
Undecided
SELECT count( gender )
FROM _members
WHERE gender =0
Example Of Block:
Males: 797
Females: 345
Undecided: 103
Edit:
Came up with something but its prob not the best way of doing it hehe...
if anyone knows a better way let me know ;)
$request = db_query("SELECT count( gender ) FROM smf_members WHERE gender =1", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
echo '<table border="0" cellpadding="0" cellspacing="2" width="100%">';
while($row = mysql_fetch_assoc($request)){
echo '<b>Total Males:</b> <font color=#1503BD>' . $row['count( gender )'] . '</font><br />';
}
mysql_free_result($request);
}
$request = db_query("SELECT count( gender ) FROM smf_members WHERE gender =2", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
while($row = mysql_fetch_assoc($request)){
echo '<b>Total Females:</b> <font color=#E61EFE>' . $row['count( gender )'] . '</font><br/>';
}
mysql_free_result($request);
}
$request = db_query("SELECT count( gender ) FROM smf_members WHERE gender =0", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
while($row = mysql_fetch_assoc($request)){
echo '<b>Undecided:</b> <font color=#000000>' . $row['count( gender )'] . '</font>';
}
echo '</table>';
mysql_free_result($request);
}
global $db_prefix;
$result = db_query("
SELECT COUNT(*) AS totalMembers, gender
FROM {$db_prefix}members
GROUP BY gender", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
$gender[$row['gender']] = $row['totalMembers'];
isset($gender[0]) ? null : $gender[0] = 0;
isset($gender[1]) ? null : $gender[1] = 0;
isset($gender[2]) ? null : $gender[2] = 0;
echo "
<b>Males:</b> $gender[1]<br />
<b>Females:</b> $gender[2]<br />
<b>Undecided:</b> $gender[0]<br />
";
Thanks JPDeni, i was doing it the loooooooooong way! haha :up:
Quote from: Maxâ„¢ on January 10, 2007, 02:28:47 PM
Thanks JPDeni, i was doing it the loooooooooong way! haha :up:
I can't tell you how many times I do it that way Max lol. Then to see someone else do it with half the code....
:) It's just experience. I used to write things the long way around, too, and still do often. But I've come to the point where I look to make as few calls to the database as possible. Sorta like when someone is going to the grocery store. If they're going for milk, might as well have them pick up bread, butter and cheese at the same time. ;)
Also, I cheat. I looked at the code in the Stats.php file. :2funny:
Hi all,
Thanks to Max and JPDeni for this excellent snippet.
I add a little piece of code to mine (just a link really) which allows a member to check they have updated their profile with the correct gender.
Quoteglobal $db_prefix, $scripturl, $context;
$result = db_query("
SELECT COUNT(*) AS totalMembers, gender
FROM {$db_prefix}members
GROUP BY gender", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($result))
$gender[$row['gender']] = $row['totalMembers'];
isset($gender[0]) ? null : $gender[0] = 0;
isset($gender[1]) ? null : $gender[1] = 0;
isset($gender[2]) ? null : $gender[2] = 0;
echo "
Males: $gender[1]
Females: $gender[2]
Undecided: $gender[0]
";
echo '
<a href="', $scripturl ,'?action=profile;u=', $context['user']['id'] ,';sa=forumProfile">Check Yours Now!</a>
';
I have another TP/SMF forum at www.farnworthgrammar.com which was originally a Snitz forum, and as a result none of the 1000+ members had a gender entered. This has been helpful to (slowly) rectify that problem.
What would really take this snippet forward is if the male, female and undecided bullets were hyperlinked to the memberlist, which then listed all the males, females or undecided ;D
Happy New Year!
Regards,
Wilsy.
how can we make default button before Male,Females,Undecided text?
Replace or add to this code with your image tag.
<b>Males:</b>
Quote from: IchBinâ,,¢ on January 02, 2008, 01:04:59 AM
Replace or add to this code with your image tag.
<b>Males:</b>
using html?
Of course! :) Thats the only way you can display an image in SMF unless you use flash or something.
:up: :laugh:
tq....
Any UPDATE for latest SMF rc4? Coz all genders counts 0
I think that all is needed is to change db_query to tpdb_query in the code.
Hope somebody can make change.
Quote from: QUBBAH on December 01, 2010, 03:39:59 AM
Hope somebody can make change.
You can't make the change yourself?
Please make an effort Qubbah. :o
Did you used to be mrCare on the old forum ?
;D
Im mrcare...
I try to use smfunc database... but i think i dont know soo well..
sorry..
hope somebody can help.
QUBBAH, I gave you the instructions on how to fix the problem. There is nothing you need to do with smcFunc.
Might not be too clear to someone who is ESL..
QUBBAH, you have code in the block, look in this code and you will see: db_query
Every time you see that, change it to this: tpdb_query
Then save the block.
Yes.. thanks for all...
got it.