Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP: A "Rank" System

    I have a mysql database that consists of users. In that database, there is a "score" column. I want to make a profile for the users, but it will show their rank. I don't want to do this server-sided, so i'm trying to do it from the profile page itself. This is my current code:

    PHP Code:
    $sql3 mysql_query("SELECT * FROM members ORDER BY score DESC") or die("Could not allocate information!");
        
    $rank 0;
        while(
    mysql_fetch_assoc($sql3)){
          
    $rank++;
        }
        echo 
    "<b>Rank: </b>#$rank<br/>"
    Ive also tried:

    PHP Code:
    $sql3 mysql_query("SELECT * FROM members ORDER BY score DESC") or die("Could not allocate information!");
        
    $rank 0;
        while(
    mysql_fetch_assoc($sql3)){
          
    $rank++;
          echo 
    "<b>Rank: </b>#$rank<br/>";
        } 
    Either way out, every user has the same rank, #2. Is there any way for me to do this? And if you need more information, please just comment. Thanks.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    the echo would need to be inside the while,

    try array instead of assoc and add a variable like this
    PHP Code:
     $rank 0;
        while(
    $row mysql_fetch_array($sql3)){
          
    $rank++;
          echo 
    "<b>Rank: </b>#$rank<br/>";
        } 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •