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?

Link to comment
Share on other sites

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		  
	 }
  ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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