duncan_cowan Posted August 23, 2006 Share Posted August 23, 2006 Is it possible to order a mysql table and then display the top 10 rows? Link to comment Share on other sites More sharing options...
aspnetguy Posted August 23, 2006 Share Posted August 23, 2006 SELECT * FROM tableName LIMIT 10 Link to comment Share on other sites More sharing options...
duncan_cowan Posted August 23, 2006 Author Share Posted August 23, 2006 i would like it to order a colum before it displays the top 10 Link to comment Share on other sites More sharing options...
justsomeguy Posted August 23, 2006 Share Posted August 23, 2006 You can use the ORDER BY clause to do that: SELECT * FROM tableName ORDER BY column LIMIT 10 Link to comment Share on other sites More sharing options...
duncan_cowan Posted September 22, 2006 Author Share Posted September 22, 2006 i have added this code to a page <?phprequire 'protected/db_connect.php';$query = "SELECT * FROM armies ORDER BY strength DESC LIMIT 10";$result = mysql_query($query) or die("error couldnt execute query");echo "<table border='0'> <tr> <td><center><font color='#FFFFFF'>Name</td> <td><center><font color='#FFFFFF'>Strength</td> </tr>";while ( $row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><center><font color='#FFFFFF'>" . $row['army name'] . "</td>"; echo "<td><center><font color='#FFFFFF'>" . $row['strength'] . "</td>"; echo "</tr>"; }echo "</table>";?> but when i run it it displays the numbers in this order: 9 7 7 6 5 4 3 2 1211why? Link to comment Share on other sites More sharing options...
aspnetguy Posted September 22, 2006 Share Posted September 22, 2006 is the field "strength" defined as INT? Link to comment Share on other sites More sharing options...
reportingsjr Posted September 22, 2006 Share Posted September 22, 2006 It will have to be defined as a type that can be ordered, like text wont work. Link to comment Share on other sites More sharing options...
duncan_cowan Posted September 23, 2006 Author Share Posted September 23, 2006 thanks alot Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now