Cocodrilo Posted April 3, 2016 Share Posted April 3, 2016 How do i something like this .. ? local consulta = dbQuery(myCallback,db,"SELECT * FROM acc_table") local resultado = dbPoll( consulta, -1 ) for _, v in ipairs(resultado) do local acc = v['account'] local playerAccount = getPlayerAccount ( getAccountName(acc) ) setAccountData(playerAccount,"Money", 1000) end * I save 'getPlayerMoney' into the "Money" accountData. I want to set that money to accounts who are in the table in the column 'account'. Link to comment
Anubhav Posted April 4, 2016 Share Posted April 4, 2016 local consulta = dbQuery(myCallback,db,"SELECT * FROM acc_table") local resultado = dbPoll( consulta, -1 ) for _, v in ipairs(resultado) do local acc = v['account'] local playerAccount = getAccount( acc ) setAccountData(playerAccount,"Money", 1000) end Link to comment
Simple0x47 Posted April 6, 2016 Share Posted April 6, 2016 local consulta = dbQuery(myCallback,db,"SELECT * FROM acc_table") local resultado = dbPoll( consulta, -1 ) for _, v in ipairs(resultado) do local acc = v['account'] local playerAccount = getAccount( acc ) setAccountData(playerAccount,"Money", 1000) end Use pairs it's better Link to comment
Simple0x47 Posted April 6, 2016 Share Posted April 6, 2016 local consulta = dbQuery(myCallback,db,"SELECT * FROM acc_table") local resultado = dbPoll( consulta, -1 ) for _, v in ipairs(resultado) do local acc = v['account'] local playerAccount = getAccount( acc ) setAccountData(playerAccount,"Money", 1000) end Use pairs it's better Link to comment
Noki Posted April 7, 2016 Share Posted April 7, 2016 No, pairs is never faster than ipairs or a simple sequential loop (for i = 1, #table do). If you're iterating over a list with perfect pairs (sequentially, where there are no nil pairs), use ipairs or the other sequential loop. The only time when you ever use pairs is when the indexes are not integers or you have imperfect pairs. http://stackoverflow.com/questions/1258 ... s-in-table http://stackoverflow.com/questions/8955 ... a-for-loop Since the OP is iterating over a polled SQL result, the resultant table will have perfect pairs. He can use ipairs or i = 1, #table for optimal speed. Link to comment
Noki Posted April 7, 2016 Share Posted April 7, 2016 No, pairs is never faster than ipairs or a simple sequential loop (for i = 1, #table do). If you're iterating over a list with perfect pairs (sequentially, where there are no nil pairs), use ipairs or the other sequential loop. The only time when you ever use pairs is when the indexes are not integers or you have imperfect pairs. http://stackoverflow.com/questions/1258 ... s-in-table http://stackoverflow.com/questions/8955 ... a-for-loop Since the OP is iterating over a polled SQL result, the resultant table will have perfect pairs. He can use ipairs or i = 1, #table for optimal speed. 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