Jump to content

[SOLVED] Find out how many people have a certain attribute


DeanWhitehouse

Recommended Posts

Ok this is a logic problem.

 

I need to find out how many users have a certain rank (which is got from the users exp), and to add to the confusion once i have done that i need to print on screen the percentage of users with that rank.

 

The ranks are also dynamic.

 

To explain better with diagrams :)

 

Diagram 1:

Rank 1 50%(400)

Rank 2 25%(200)

Rank 3 25%(200)

 

Diagram 1 is what it should look like :)

 

At the moment i was planning on looping through each user, and adding their rank to an array and then looping through the ranks and then i don't know :s

 

Any ideas?

I ended up doing, it just came to me :)

A lot simpler than i thought

  <?php
	$sql = mysql_query("SELECT * FROM rank ORDER BY end DESC");
	while($rows = mysql_fetch_assoc($sql))
	{
		$sql1 = "SELECT exp FROM user_stats WHERE exp >= '".$rows['start']."' AND exp <= '".$rows['end']."'";
		$sql1 = mysql_query($sql1);
	?>
      <tr>
        <td><?=$rows['rank']?></td>
        <td><?=round((mysql_num_rows($sql1)/$total_users)*100)?>% (<?=mysql_num_rows($sql1)?>)</td>
      </tr>	
	<?php		  
	 }
  ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.