-2

i have a query here, and I am trying to sort the order they output by the column "rank", what would i add to my query exactly to do this? here is my code:

$query = $pdo->prepare('SELECT * 
                        FROM leaderboards 
                        WHERE game_id=2 AND mode_id=1 and map_id=15 
                        LIMIT 0, 100');
TylerH
  • 20,799
  • 66
  • 75
  • 101
  • Possible duplicate of [MYSQL - ORDER BY & LIMIT](https://stackoverflow.com/questions/4708708/mysql-order-by-limit) – WMRamadan Feb 15 '19 at 20:21

2 Answers2

2

If you want to order by a specific column, use the ORDER BY clause.

$query = $pdo->prepare('SELECT * 
                        FROM leaderboards 
                        WHERE game_id=2 AND mode_id=1 and map_id=15 
                        ORDER BY rank
                        LIMIT 0, 100');
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

you even can use more that one field to sort, See below

$query = $pdo->prepare('SELECT * 
                        FROM leaderboards 
                        WHERE game_id=2 AND mode_id=1 and map_id=15 
                        ORDER BY rank, rank2
                        LIMIT 0, 100'); 
MR.Internet
  • 547
  • 4
  • 19