[HELP] Get data from the database (Fx vRP server)

Im trying to get some data out from the database on my Fx vRP server.

So made this, and trigger it from client on a keypress

MySQL.createCommand("vRP/get_check", "SELECT licens FROM vrp_users WHERE id = @id")

RegisterServerEvent("mb_check")
AddEventHandler("mb_check", function()

       local user_id = vRP.getUserId({source}, function(user_id) return user_id end)
       local id = user_id
	MySQL.query("vRP/get_check", {id = id}, function(licens, affected)
	if #rows > 0 then
		for k,v in pairs(rows) do
			local row = v
		end
		vRPclient.notify(user_id,{"the row is  "..row})
        end
end)

licens = 0 in the databas.
it stops at
vRPclient.notify(user_id,{"mysql_virker "…row}). With this error
attempt to concatenate a table value (upvalue ‘row’)

what am i doing wrong

I’m crying…

getUserId doesn’t require a function as a parameter, it just wants the source. And, it doesn’t want “source” inside a table either.

Why??? Just leave it as user_id there’s no need for this line at all.

I haven’t have a look at how vRP does SQL requests but, I’ll assume you’ve done this right (just change id = id to id = user_id as it avoids all ambiguity).

OK. So, for each value in the database that has been returned set “row” to value (for this current iteration only).

What’s row? It only existed inside that loop and, this isn’t inside said loop. Put it inside there and it should show you what “row” is.

3 Likes

if i understand you correctly, then i shoot do it like this :slight_smile:

if #rows > 0 then
  for k,v in pairs(rows) do
    local row = v	
    vRPclient.notify(user_id,{"the row is  "..row})
  end
end

but now i get
Failed to execute thread: server.lua:24: attempt to concatenate a table value (local ‘row’)