I need a little help thinking of the process of this... I want to create a ranking system based off points each of my user has. I dont need help assigning points to the user just how I would pull their ranking based off the points.

I have a user table where I will add a points column for each users. To pull the Top users I know I could do something like this:

SELECT * FROM `users` ORDER BY `points`

Now say on a users profile I'm just pulling the information such as the points... how would I find out what they rank against the rest of the users like ranked #3 or w/e.

(Also if there is a more logical setup I would appreciate your input) Thank you!

    i think you need to get the row number associated with their entry. I know you can do it in Oracle with ROWNUM but to my knowledge MySQL doesn't have such a feature. I could be wrong. You could pull the results into an associative array:

    $query = "SELECT * FROM 'users' ORDER BY 'points'";
    $result = mysql_query($query);
    $rank = mysql_fetch_assoc($result);
    

    And then use the key() function which is used to find the key position of an item in an associative array.

      Ahh okay... Ill give that a try. Thank you 🙂

        Write a Reply...