Jump to content

setAccountData - accounts in table


Recommended Posts

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
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
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 :P

Link to comment
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 :P

Link to comment

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

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

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