Jump to content

Recommended Posts

 

(Modes I am not sure if this maybe needs to go in the Mysql category or if it should stay in this category)

  Hello,

 

  What I am doing is I have a database (mysql and I use php5 in case anyone needs to know) of userid's and points. So I am connecting to the dbase and listing only the top 100 users who have the highest points. My issues is once I display the users on the page I would like to number each resulting row starting at 1 and going of course to 100. I know I have to probably use a foreach() line but not sure how to structure it. Can anyone offer any help? my current sql code is

 

$sql = "SELECT max(POINTS) top_player, POINTSLIST.USERID, USERS.USERNAME FROM POINTSLIST 
               INNER JOIN USERS ON POINTSLIST.USERID = USERS.USERID where POINTSLIST.USERID > 16 GROUP BY POINTS 
               ORDER BY top_player DESC LIMIT 100";
       $result = $conn->query($sql);
       while($row = $result->fetch_assoc())
       {
       extract($row);
   $sql2 = "SELECT FNAME, LNAME from PLAYERS where USERID='$USERID'";
   $result2 = $conn->query($sql2);
       while($row2 = $result2->fetch_assoc())
       {
       extract($row2);   
   if ($alternate == "1") {  
      $colour = "#C1C1C1";  
      $alternate = "2";  
      }else{  
      $colour = "#FFF0F0";  
      $alternate = "1";  
      }  
       echo "<tr bgcolor=$colour><td>$FNAME $LNAME</td><td>$top_player</td></tr>";
   }
       }

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/64781-need-help-to-number-mysql-row-result/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.