Millar Posted August 8, 2006 Share Posted August 8, 2006 I have this piece of code so far to order by the power...[code]$result = mysql_query("SELECT * FROM reg ORDER BY power DESC") ; print "<table>";print "<tr> <th>Name</th></tr>";// keeps getting the next row until there are no more to getwhile($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table print "<tr><td><a href='index.php?act=stats&id=" . $row['id'] . "'>"; print $row['user']; print "</a></td></tr>"; } print "</table>";[/code]But, how can I get the position in the array the particular name is, so it is displayed like a ranking by power.Thanks. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 8, 2006 Share Posted August 8, 2006 You could do this in MySQL, but it sounds like a PHP counter variable would be more useful. Quote Link to comment Share on other sites More sharing options...
Millar Posted August 8, 2006 Author Share Posted August 8, 2006 How would I do it in PHP? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 8, 2006 Share Posted August 8, 2006 To create a counter variables use this:[code]// prepare out counter variable:$i = 1;while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table print "<tr><td>{$i} - <a href='index.php?act=stats&id=" . $row['id'] . "'>"; print $row['user']; print "</a></td></tr>"; // now we increment the counter var by 1 $i++;} [/code]That produce this:1 - [name here]2 - [name here]3 - [name here]etcObiviosly name here will be replaced with the name in the database Quote Link to comment Share on other sites More sharing options...
Millar Posted August 8, 2006 Author Share Posted August 8, 2006 Kool, thanks. Quote Link to comment 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.