Stalingrad Posted October 14, 2012 Share Posted October 14, 2012 Hi! I have some PHP and MySQL code here. I am trying to set up this table displaying users scores. I want to grab from a table in a sepecific row and order the row by the top to bottom, but only the TOP 10. Like for example, lets say I wanted only 3 for this example to keep it simple. (even though I wnat 10, thisexample will keep things simple and not waste any time)... I have a table called "user". Row Name: id name score 1 julie 100 2 sam 80 3 james 35 I want to grab both the username AND the score, and order by the score, larger score to bottom. Just like I showed. Here is my code: if($table == "Avatar") { $avq = "SELECT avatarcount FROM users"; echo "Top Scores<br><br>"; } I appreciate any help! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/269461-i-want-to-grab-10-rows-and-order-by-top-10/ Share on other sites More sharing options...
berridgeab Posted October 14, 2012 Share Posted October 14, 2012 (edited) $avq = "SELECT avatarcount FROM users ORDER BY score DESC LIMIT 0,10"; $avq = "SELECT id, name, score FROM users ORDER BY score DESC LIMIT 0,10"; Edited October 14, 2012 by berridgeab Quote Link to comment https://forums.phpfreaks.com/topic/269461-i-want-to-grab-10-rows-and-order-by-top-10/#findComment-1385197 Share on other sites More sharing options...
Stalingrad Posted October 14, 2012 Author Share Posted October 14, 2012 Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/269461-i-want-to-grab-10-rows-and-order-by-top-10/#findComment-1385199 Share on other sites More sharing options...
Stalingrad Posted October 14, 2012 Author Share Posted October 14, 2012 (edited) Oh wait, it's ordering them by the first number, not the whole number... I'm getting this: 99 84 3455 How do I fix this one? Thanks. :s Ah, I got it. It seems I didn't have the row set as "INT" in my database, it was set as "VARCHAR". Thank you for the help. It works fine now. ^^ Edited October 14, 2012 by Stalingrad Quote Link to comment https://forums.phpfreaks.com/topic/269461-i-want-to-grab-10-rows-and-order-by-top-10/#findComment-1385202 Share on other sites More sharing options...
DarkerAngel Posted October 14, 2012 Share Posted October 14, 2012 Oh wait, it's ordering them by the first number, not the whole number... I'm getting this: 99 84 3455 How do I fix this one? Thanks. :s Is the table column set to varchar or INT? Quote Link to comment https://forums.phpfreaks.com/topic/269461-i-want-to-grab-10-rows-and-order-by-top-10/#findComment-1385204 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.