Klance Posted April 12, 2008 Share Posted April 12, 2008 I know you use ORDER BY but i'm not sure about to use it. I want the records to come out on a table ordered by the field Score. Here is what I have: <?php $host = "localhost"; $user = "root"; $pass = "*****"; $db = "GHScores"; $conn = mysql_connect($host, $user, $pass) or die("Unable to connect!") ; mysql_select_db($db) or die("Unable to select database!"); $game = $_GET['game']; $console = $_GET['console']; $diff = $_GET['diff']; $song = $_GET['song']; $query = "SELECT * FROM $game WHERE console = '$console' AND diff = '$diff' AND song = '$song' ORDER BY 'Score'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "<br><center><table border = '1' bordercolor='gray' cellpadding='3' cellspacing='0'> <tr> <th>Song</th> <th>User</th> <th>Score</th> <th>% of Notes Hit</th> <th>Note Streak</th> <th>Timestamp</th> <th>Comment</th> <th>Picture</th> <th>Video</th> </tr></center>"; if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td><center>".$row['Song']."</td></center>"; echo "<td><center>".$row['User']."</td></center>"; echo "<td><center>".$row['Score']."</td></center>"; echo "<td><center>".$row['NotesHit']."</td></center>"; echo "<td><center>".$row['Streak']."</td></center>"; echo "<td><center>".$row['Timestamp']."</td></center>"; echo "<td><center>".$row['Comment']."</td></center>"; echo "<td><center>".$row['Picture']."</td></center>"; echo "<td><center>".$row['Video']."</td></center>"; echo "</tr>"; } echo "</table>"; } else { echo "None found!"; } ?> I'm not sure why this doesn't work... Link to comment https://forums.phpfreaks.com/topic/100848-solved-how-do-i-order-my-mysql-records/ Share on other sites More sharing options...
dark_mirage Posted April 12, 2008 Share Posted April 12, 2008 If Score is a field name, you need to change the line: $query = "SELECT * FROM $game WHERE console = '$console' AND diff = '$diff' AND song = '$song' ORDER BY 'Score'"; to $query = "SELECT * FROM $game WHERE console = '$console' AND diff = '$diff' AND song = '$song' ORDER BY Score DESC"; DESC is descending, if you want them ascending, it would be ASC i think, im pretty new to php but i think thats your problem. Hope it helps Link to comment https://forums.phpfreaks.com/topic/100848-solved-how-do-i-order-my-mysql-records/#findComment-515705 Share on other sites More sharing options...
Klance Posted April 12, 2008 Author Share Posted April 12, 2008 yeah that was it, thanks Link to comment https://forums.phpfreaks.com/topic/100848-solved-how-do-i-order-my-mysql-records/#findComment-515707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.