Tables are very useful if you know how to use them but I don't...
I have this code:
[CODE]
local status = databaseObject:query("SELECT user_upgrade_id FROM xf_user_upgrade_active WHERE user_id = '" .. ply:GetNWInt("userid") .. "'") --Look for status var on the forums
status.onSuccess = function(q)
local status = status:getData()
if status[1] ~= nil then
local tabstatus = table.ToString( status )
Msg(tabstatus.."\n") -- testing shit
--Msg(status[user_upgrade_id].."\n") --Testing shit
local tabformattedstatus = string.sub(tabstatus, 19, -5) -- Bypass to my table "noobness" problems
ply:SetNWInt("rank", tabformattedstatus)-- don't worry I have meta functions ahead
if DEBUG == true then
ply:ColChat("DDB", Color(0,0,255), "You exist on the forums!")-- DEBUG
end
else
ply:SetNWInt("rank", "0")
end
status.onError = function(q,e) ply:ColChat("DDB", Color(0,0,255), " FATAL ERROR:" ..e) end
end
status:start()
[/CODE]
Status table:
[CODE]
{user_upgrade_id = 99,}
[/CODE]
What I want to know is, How to get values from tables? I want the value 99...
Thank you in advance...
youtablename.user_upgrade_id or youtablename[ "user_upgrade_id" ]
[QUOTE=Robotboy655;41011390]youtablename.user_upgrade_id or youtablename[ "user_upgrade_id" ][/QUOTE]
And what if the table has 2 values for user_upgrade_id. how do I get the 2nd value?
[CODE]
{{user_upgrade_id = 99,}, {user_upgrade_id = 88,},}[/CODE]
Is it youtablename["user_upgrade_id"[2]]?
[lua]
yourtablename[2].user_upgrade_id
[/lua]
Also you only need commas to seperate elements, not after every single element.
So instead of
[lua]
{{user_upgrade_id = 99,}, {user_upgrade_id = 88,},}
[/lua]
do
[lua]
{{user_upgrade_id = 99}, {user_upgrade_id = 88}}
[/lua]
[QUOTE=ollie;41012014][lua]
yourtablename[2].user_upgrade_id
[/lua]
Also you only need commas to seperate elements, not after every single element.
So instead of
[lua]
{{user_upgrade_id = 99,}, {user_upgrade_id = 88,},}
[/lua]
do
[lua]
{{user_upgrade_id = 99}, {user_upgrade_id = 88}}
[/lua][/QUOTE]
Can I do this?
[CODE]yourtablename[2]["user_upgrade_id"][/CODE]
Yes, you can always use either .key or ["key"]
[QUOTE=ollie;41012279]Yes, you can always use either .key or ["key"][/QUOTE]
Thank you everyone, I got it now.
[SOLVED]
Sorry, you need to Log In to post a reply to this thread.