mjfroggy Posted August 14, 2007 Share Posted August 14, 2007 (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 Quote Link to comment https://forums.phpfreaks.com/topic/64781-need-help-to-number-mysql-row-result/ Share on other sites More sharing options...
teng84 Posted August 14, 2007 Share Posted August 14, 2007 sql is not needed in your prob simply add an increment something like $CTR++; and echo that beside the name Quote Link to comment https://forums.phpfreaks.com/topic/64781-need-help-to-number-mysql-row-result/#findComment-323188 Share on other sites More sharing options...
Barand Posted August 14, 2007 Share Posted August 14, 2007 You could also use that same $CTR to alternate the colours $colour = $CTR % 2 ? '#C1C1C1' : '#FFF0F0'; Quote Link to comment https://forums.phpfreaks.com/topic/64781-need-help-to-number-mysql-row-result/#findComment-323279 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.