Jump to content

Mysql Top 25 Values


Sande

Recommended Posts

Posted

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

Posted

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 

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...