update everyone's sql table (for in loop)

I have a whole bunch of stuff for my gamemode worked out (ie reading writing and updating SQL tables) but how do I do everyone’s at once?

Specifically im trying to do something similar to the way darkRP’s wage system works, where it gets the connected players steamID’s, uses them to load the players’ current wage (saved in the sql db) and adds the wage to their current wallet amount (also from the db) then saves their new wallet amount accordingly back into the db and sets everyone’s NWInt so the client’s wallet display reflects the change, all run on a function run by a timer.

I know the SQL but I cant find a detailed enough tutorial on the for k,v in pairs loop and how to load the connected players’ data into a table to do so.

any help much appreciated <3

It has been a while, but last time I checked your DarkRP wage depended on the job you were playing and thus didn’t need any saving? Anyway you would just loop trough all of the players, here’s how.

[lua]
for k,v in pairs( player.GetAll() ) do – Looping trough the table of all players, k is the index and v is the player itself.
– Do stuff here. v is an idividual player, don’t bother with k.
v:Kill() – An example xD
end
[/lua]

wow that’s easy as shit.

so V = what exactly? the same as the ply argument?

Exactly. For each element of the table, v will represent the value. Since it’s a table of all players v will be, in turn, all of the players.

Notes:
1- It could be anything, it’s just 2 variables you make up and throw in there. But by convention most people use k,v as it stands for key,value.

2- If you want to nest a loop inside another you’ll have to use another name, but you can still refer to the variables used higher up.

[lua]
local RandomNumbers = [12,2,63,4]

for k,v in pairs( player.GetAll() ) do
– Do stuff here
for i,j in pairs( RandomNumbers )
v:SetHealth( v:GetHealth() + j )
end

end[/lua]

k is the table index, and v is the value of the table, which in this case is the player entity (ply)

thanks guys