Tmysql 4 - Problem with "for k, v in pairs results"
4 replies, posted
Hello all,
Sorry for disturbing you,
Can you help me with my problem ?
[code]
function MakeMyItem(Player)
DB:Query("SELECT `id`, `amount`, `npc_id` FROM `item_list`", function ( misc_info )
if misc_info[1].data[1] && mis_infoc[1].data[1].id then
for k, v in pairs(misc_info) do
local chance = math.Rand(0, 6)
--PrintTable(misc_info)
--print(misc_info[1].data[1].id)
--print(misc_info[1].data[1].amount)
--PrintTable(v)
--print(v.data[1].id)
if v[1] == "11" || v[1] == "10" || v[1] == "2" || v[1] == "78" then
chance = math.Rand(0, 40)
end
if math.Round(chance) < 2 && tonumber(v[2]) < 15 then
DB:Query("UPDATE `item_list` SET `amount`='" .. tostring(tonumber(v[2]) + 1) .. "' WHERE `id`='" .. v[1] .. "'")
end
end
end
end)
end
[/code]
With tmysql 3, it works but with tmysql 4 the v[1] is nil
Thanks you
Are you sure v is a table?
PrintTable(v)
Result :
[code]
affected = 26
data:
1:
npc_id = 1
amount = 15
id = 1
2:
npc_id = 1
amount = 9
id = 2
3:
npc_id = 1
amount = 15
id = 3
[/code]
So what i have to change ?
old
[code]
if v[1] then
[/code]
to
[code]
if v.data[1].npc_id then
[/code]
but the [1] cause me to select only one table in data
?
[editline]18th December 2016[/editline]
- Problem solved by Acecool
He is a great teacher !!
Thanks you Acecool.
Sorry, you need to Log In to post a reply to this thread.