SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Mysql Row Id
-
Jan 24, 2005, 01:15 #1
Mysql Row Id
Wasn't sure whether to put this in MySQL or PHP but...
I'm writing a high score list in php and I need to figure out the rank of the player. Here is the relavent code:
Code:if(empty($_GET['skill']) || $_GET['skill'] == 'overall') { $mysqlQuery = @mysql_query("SELECT * FROM `highscores` ORDER BY `skilltotal` DESC LIMIT 0, 20", $mysqlConnect) or die("DB Select Error: ". mysql_error()); $_GET['skill'] = 'overall'; } else $mysqlQuery = @mysql_query("SELECT * FROM `highscores` ORDER BY `". $skillInfo[$_GET['skill']]['columnName'] ."` DESC LIMIT 0, 20", $mysqlConnect) or die("DB Select Error: ". mysql_error());
Code:<tr><th style="font-size: 1.2em; width: 33%;">Rank</td><th style="font-size: 1.2em; width: 33%;">Name</th><th style="font-size: 1.2em; width: 33%;">Level</th></tr> <?php while($row = @mysql_fetch_array($mysqlQuery)) echo(" <tr><td>0</td><td>". $row['username'] ."</td><td>". $row[$skillInfo[$_GET['skill']]['columnName']] ."</td></tr>");
Code:Index User Level 0 abc 99 1 def 78 2 ghi 63 3 jkl 22
Any help would be appreciated.- Saj
-
Jan 24, 2005, 06:07 #2
Hi,
there is no such thing as a row id in MySQL. You could use user variables or you could add two lines to your PHP:
Code:<?php $count = 1; while($row = @mysql_fetch_array($mysqlQuery)) { echo("<tr><td>$count</td><td>". $row['username'] ."</td><td>" . $row[$skillInfo[$_GET['skill']]['columnName']] ."</td></tr>"); $count++; }
Never ascribe to malice,
that which can be explained by incompetence.
Your code should not look unmaintainable, just be that way.
-
Jan 24, 2005, 08:19 #3
Hmm, I thought there was. Oh well then. I suppose I'd have to do without it. I guess my idea wouldn't have worked anyway...Thanks for your help though
- Saj
-
Jan 24, 2005, 13:22 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
are you asking how to get the rank of a specific row?
e.g. what is joe's position out of all users, based on his level?
for this type of query, you do not want to return the entire table, append a rownumber, and then loop until you find joe
i can give you the sql for this, if this is what you want
Bookmarks