How do you arrange a group of numbers in a database by highest first?
Like Row- Score: Jimmy Score- 340 Joe Score- 347 Alex Score- 340
etc.
Use the DESC keyword to order them descending. ASC for ascending.
mysql.com for more info. 🙂
Yea, I do that... but the numbers vary... If someone has a score of 9, it will be displayed first over a score of 200. And I want the 200 to be displayed 1st
Might help if you posted your query.
SELECT name, score FROM tblRecord ORDER BY score DESC
This will return an object containing an array with name and score ordered by score descening.
heres my code
$sql = "SELECT * FROM roster WHERE game='{$_REQUEST['game']}' and status='active' order by match_score desc";
And heres what it spits out...
http://www.joint-ops.net/xfactor/stats.php?game=mohaa
Wow -- that's pretty FUB'd... Can you post the code after that which does the query and output?
<?php // Connect to the database $db = mysql_connect("localhost","xfactor","pw"); mysql_select_db (xfactor); // Ask the database for the information from the squadlinks table $sql = "SELECT * FROM roster WHERE game='{$_REQUEST['game']}' and status='active' order by match_score desc"; if (!$result = mysql_query($sql)) { print "Invalid query ($sql) : " . mysql_error(); exit; } while ($row = mysql_fetch_assoc($result)) { print "<center><table width=598 cellpadding=2 cellspacing=0> <tr><td width=12%><font face=verdana size=1 color=FFFFFF><B><a href=player.php?soldierid={$row['soldierid']}>{$row['name']}</a></B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_kills']}</B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_deaths']}</B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_ratio']}</B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_mapsplayed']}</B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_zonetime']}</B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_flags']}</B></td> <td width=12%><font face=verdana size=1 color=FFFFFF><center>{$row['match_score']}</B></td></tr> <td width=100% colspan=8 bgcolor=454545 height=1></td></tr> </table>"; } ?>
Out of curiosity -- is your datatype for the score field an integer or text? Like varchar...
It looks like a text because it is going in descending order for text:
9 2 1
Check datatype and lemme know?
its varchar
Ya, change it to Int -- that'll support a score up to 2 billion or so, I believe.