DeanWhitehouse Posted January 3, 2009 Share Posted January 3, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/139356-solved-find-out-how-many-people-have-a-certain-attribute/ Share on other sites More sharing options...
revraz Posted January 3, 2009 Share Posted January 3, 2009 You can do a count and group by rank, and use a little division to get the %. Quote Link to comment https://forums.phpfreaks.com/topic/139356-solved-find-out-how-many-people-have-a-certain-attribute/#findComment-728900 Share on other sites More sharing options...
DeanWhitehouse Posted January 3, 2009 Author Share Posted January 3, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139356-solved-find-out-how-many-people-have-a-certain-attribute/#findComment-728903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.