TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,911
  • Total Topics: 21,307
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 360
  • Total: 361
  • tino

Total Males/Females Block

Started by Max, January 10, 2007, 01:40:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Max

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);
  }

JPDeni


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 />
";

Max


Thanks JPDeni, i was doing it the loooooooooong way! haha  :up:

IchBin

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....

JPDeni

:) 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:


wilsy

#5
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.

alhaudhie

how can we make default button before Male,Females,Undecided text?

IchBin

Replace or add to this code with your image tag.
<b>Males:</b>


alhaudhie

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?

IchBin

Of course! :) Thats the only way you can display an image in SMF unless you use flash or something.

This website is proudly hosted on Crocweb Cloud Website Hosting.