zackcez Posted July 20, 2008 Share Posted July 20, 2008 I know that this will not work...but here's what I have: <?php $user = Zack; function getRank($user){ $query = "SELECT * FROM user ORDER BY score"; $rank = 0; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $rank++; $user_rank = "$rank WHERE username='$user'"; } } ?> What I'm trying to do is make it find the rank for every user but store the one for a certain user (Zack). If anyone knows how I can make that work or a better way to do it, please post here Quote Link to comment https://forums.phpfreaks.com/topic/115745-solved-phpmysql-rankings/ Share on other sites More sharing options...
zackcez Posted July 20, 2008 Author Share Posted July 20, 2008 Well, I'm not sure if this would work but I was messing around and I came up with this: <?php $user = Zack; function getRank($user){ $query = "SELECT * FROM user"; $rank = 0; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $rank++; $test_rank[" . $row['username'] . "] = $rank; echo $test_rank[$user]; } } getRank($user); ?> Anyone Know if that'd work? Quote Link to comment https://forums.phpfreaks.com/topic/115745-solved-phpmysql-rankings/#findComment-595020 Share on other sites More sharing options...
Barand Posted July 20, 2008 Share Posted July 20, 2008 function getRank ($user) { $sql = "SELECT COUNT(*)+1 as rank FROM user WHERE score > (SELECT score FROM user WHERE username = '$user')"; $res = mysql_query($sql); return mysql_result($res,0); } $rank = getRank('Zack'); echo $rank; Quote Link to comment https://forums.phpfreaks.com/topic/115745-solved-phpmysql-rankings/#findComment-595029 Share on other sites More sharing options...
Barand Posted July 20, 2008 Share Posted July 20, 2008 Quote Anyone Know if that'd work? Have you considered testing it to find out? Quote Link to comment https://forums.phpfreaks.com/topic/115745-solved-phpmysql-rankings/#findComment-595034 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.