Jump to content

need help to number mysql row result


mjfroggy

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.