mysql, one row with multiple of the same values

I currently have a row called ‘uniqueid’ that contains a players steamid, but it can be in the row more than one time.

Right now I have it setup so when a player spawns, it checks to see if they are in the database, and if they are, it gives them what is in the “item” row.

It works fine if there is just one time their steam id is in the row, but when it is there more than once, it doesn’t give them all their items at once, it does it one at a time in 5 second intervals.

Is there a way to have it so it gives them all their items in the first 5 seconds, and not every 5 seconds per item?

Currently my code is:

function TestSQLFunc(ply)
	timer.Create("KeepChecking"..ply:UniqueID(), 5, 0, function()
		local check = db5:query("SELECT * FROM `test` WHERE `uniqueid`='"..ply:SteamID64().."' AND `redeemed` = '0' GROUP BY `tid`;")
		check.onSuccess = function(q, d )
			if checkQuery(q) then
				local info = q:getData()
				local redeemed = info[1].redeemed;
				local item = info[1].item;
				local tid = info[1].tid;
				if (redeemed == "0") then
					if (item == "test") then
						ply:SendLua("print('got the test')")
					elseif (item == "test2") then
						ply:SendLua("print('got test 2')")
		check.onError = function(q, e) ServerLog("Failed to check test data"..e) end
hook.Add("PlayerInitialSpawn", "TestSQLFunc", TestSQLFunc)

And it prints out

got the test
--5 seconds later
got test 2

thanks in advance

Why dont u keep one row per player, and save it as JSON instead of multiple rows?

Too much used to working with MongoDB and Node.JS, sorry XD

local redeemed = info[1].redeemed;
local item = info[1].item;
local tid = info[1].tid;
If I’m understanding your code correctly, you’re only indexing the first row.
Try looping through the length of the info table, and give the item within that loop.

so would I do something like this?

	local con = table.Count(info) 
	for i = 1, #con do
	        local redeemed = info*.redeemed;
		local item = info*.item;
	        local tid = info*.tid

basically the whole part inside the if of the “queryCheck” should be inside the loop, not only the local variable definition.

A more elegant and more “luaish” solution is using ipairs:

for index, row in ipairs(info) do
  if row.redeemed ....


thanks guys, it works now.

i have one more issue.

If there are 2 of an item that are suppose to get transferred to a player when he joins, they both get applied at once. The issue with that is, sometimes they override each other.

Here is an example since that probably doesn’t make much sense: a player is queued to get $100 dollars twice in darkrp. the player joins, and gets the $100, but he only gets it once due to the darkrp money amount not updating quick enough.

how can I get the total amount he is suppose to get, add them up, and give it to them as a whole?

thanks again.

Make a local variable outside the loop, check if the action is to give money and add the money to that local variable. After the loop ends, add the money to the player.