affc Posted June 15, 2008 Share Posted June 15, 2008 Hello all, I have tried this many ways using the $Rank=0 code which will only display number 1 for every user that logs in. Is this possible in anyway to still only have the User display there row only but still have their overall rank compared to all the other members displayed? Thanx guys/girls <php $sql="SELECT *, Goals+Points AS Total FROM scoreboard ORDER BY Total DESC WHERE Member='$Memberloginname'"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ $Rank = 0; ?> Hello <? echo $rows['Member']; ?>, your current Rank out of everyone is <? echo ++$Rank; ?> <?php mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/ Share on other sites More sharing options...
MasterACE14 Posted June 15, 2008 Share Posted June 15, 2008 I use this code to rank members hourly using a cron job. <?php /*** Work out user ranks ***/ $query = mysql_query("SELECT * FROM cf_users"); while($row = mysql_fetch_array($query)){ // grab database info for each user // edit the column names below $add = $row['strikeaction'] + $row['defenceaction'] + $row['covertaction']; $result = $add / 3; // divide by number of columns to get the average score $user = $row['id']; // grab user id mysql_query("UPDATE cf_users SET score = '$result' WHERE id = '$user'"); // update the users score(average) } $x = 1; // first rank is 1 $select = mysql_query("SELECT * FROM cf_users ORDER BY score DESC"); // grab all users with there new scores while($var = mysql_fetch_array($select)){ $person = $var['id']; // grab the users ids again mysql_query("UPDATE cf_users SET rank = '$x' WHERE id = '$person'"); // give each user there rank $x++; // ranks 1, 2, 3 etc... } ?> You need a score integer column in your database for this to work. Regards ACE Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565828 Share on other sites More sharing options...
affc Posted June 15, 2008 Author Share Posted June 15, 2008 Thanx for the reply. So i guess there is not other way of doing it so that it just querys the Database and spits back what their Current Rank is? +: I dont need the Scoreboard to update any of the members details when they view it through their login, just need it to let them know what their current rank is. Not sure how this could be done really, but their scores are updated via other pages through other means. Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565844 Share on other sites More sharing options...
MasterACE14 Posted June 15, 2008 Share Posted June 15, 2008 there is probably a way. But if you want accurate information, Its better to store a 'score' at the same time for everyone on the server. Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565846 Share on other sites More sharing options...
affc Posted June 15, 2008 Author Share Posted June 15, 2008 The score is stored in the Total. I can get the Rank if I display all of the members at once and just echo $Rank but when I limit it to only display 1 member it always displays that member as Rank 1. Thought there might be a way around it? Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565848 Share on other sites More sharing options...
GingerRobot Posted June 15, 2008 Share Posted June 15, 2008 So you want rankings based on Goals+Points? Try this: $sql = "SELECT *,Goals+Points as score, (SELECT COUNT(*)+1 FROM scoreboard WHERE Goals+Points > score) as rank FROM scoreboard Member='$Memberloginname'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo 'Your rank is: '.$row['rank']; Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565850 Share on other sites More sharing options...
affc Posted June 15, 2008 Author Share Posted June 15, 2008 This displays each member and their current Rank. Is their a way just to have it remove all the other rows and just display the row of the Member? <?php $sql="SELECT *, Goals+Points AS Total FROM scoreboard ORDER BY Total DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ $Rank = 0; ?> <? echo $rows['Member']; ?> is currently rank = <? echo ++$Rank; ?> <?php mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565851 Share on other sites More sharing options...
affc Posted June 15, 2008 Author Share Posted June 15, 2008 Thanx I will give your last msg a go. Yeah I just add the Goals and Points through the SQL query. That gives me the total score anywaz will see how we go thanx, Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565852 Share on other sites More sharing options...
Barand Posted June 15, 2008 Share Posted June 15, 2008 So you want rankings based on Goals+Points? Try this: $sql = "SELECT *,Goals+Points as score, (SELECT COUNT(*)+1 FROM scoreboard WHERE Goals+Points > score) as rank FROM scoreboard Member='$Memberloginname'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo 'Your rank is: '.$row['rank']; GingerRobots query should do it if you fix it by adding "WHERE" before the " Member='$Memberloginname' " Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565853 Share on other sites More sharing options...
GingerRobot Posted June 15, 2008 Share Posted June 15, 2008 So you want rankings based on Goals+Points? Try this: $sql = "SELECT *,Goals+Points as score, (SELECT COUNT(*)+1 FROM scoreboard WHERE Goals+Points > score) as rank FROM scoreboard Member='$Memberloginname'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo 'Your rank is: '.$row['rank']; GingerRobots query should do it if you fix it by adding "WHERE" before the " Member='$Memberloginname' " Whoops. Good spot. Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565854 Share on other sites More sharing options...
affc Posted June 15, 2008 Author Share Posted June 15, 2008 Just had to add the WHERE in the sql but working perfectly, if only everyone could have seen me jumping into the sky over this code, you make it look to easy, thanx again and for anyone else that needs a working code to display their Rank use the code below works a charm, all thanx to Ginger Robot $sql = "SELECT *,Goals+Points as score, (SELECT COUNT(*)+1 FROM scoreboard WHERE Goals+Points > score) as rank FROM scoreboard WHERE Member='$Memberloginname'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); echo 'Your rank is: '.$row['rank']; Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565855 Share on other sites More sharing options...
adguru Posted June 15, 2008 Share Posted June 15, 2008 I hope the above posts are enough, however, if you still don't understand then reply here. I will send you the code. Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565986 Share on other sites More sharing options...
Barand Posted June 15, 2008 Share Posted June 15, 2008 How nice of you to jump in after it's solved and offer a solution. Link to comment https://forums.phpfreaks.com/topic/110278-solved-how-do-you-quotdisplay-users-current-rank-in-databasequot/#findComment-565999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.