Tmysql 4 - Problem with "for k, v in pairs results"

Hello all,

Sorry for disturbing you,

Can you help me with my problem ?


	
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


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 :



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


So then do you see how v[1] doesn’t exist? Since the only direct keys in that table are v.affected and v.data?

So what i have to change ?

old



if v[1] then


to



if v.data[1].npc_id then


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.