Sande Posted August 21, 2015 Share Posted August 21, 2015 Hi, i have problems to get the top 25 values from a mysql database. The first code gives me the values but i want it to be sorted like from the richests players to the poorest players with a limit of 25 player. Example. 1. 1901011$ 2. 1871110$ 3. 1681191$ etc. 1. code local btQ = dbQuery ( dbYhteys , "SELECT * FROM kayttajat ORDER BY bankmoney DESC LIMIT 25") local btR = dbPoll ( btQ, - 1 ) This is how this code returns: http://i.imgur.com/puBhwcl.jpg 2. code local btQ = dbQuery ( dbYhteys , "SELECT * FROM kayttajat ORDER BY bankmoney ASC LIMIT 25") local btR = dbPoll ( btQ, - 1 ) This code returns only 0 values. I will be thankful if some of the mysql experts help me solve this out. Searched now one day from google and cant find a working solution. http://i.imgur.com/Zoq2uMk.jpg Link to comment
Walid Posted August 21, 2015 Share Posted August 21, 2015 Try to use table.sort i will gave an example: -- get all players inside database function getAllPlayersInsideDataBase() local data = dbPoll(dbQuery(dbYhteys,"SELECT * FROM kayttajat"), -1) return data end -- Now you need to use table.sort function topRichestsPlayers() sortedTopRichestsPlayers = {} local table = getAllPlayersInsideDataBase() for a, b in pairs(table) do table.insert(sortedTopRichestsPlayers, {a, b}) end table.sort(sortedTopRichestsPlayers , function(a,b) return a[2] > b[2] end) end Link to comment
MIKI785 Posted August 21, 2015 Share Posted August 21, 2015 That's probably because the datatype of column bankmoney is varchar or other text. Make it int and it will work. Link to comment
Sande Posted August 21, 2015 Author Share Posted August 21, 2015 That's probably because the datatype of column bankmoney is varchar or other text. Make it int and it will work. Thanks your solution worked perfectly. Link to comment
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