Hi everyone,
I’m trying to figure out why I can’t access the fields containing in my MySQL request :
Here is the request I execute on player spawn.
RegisterServerEvent('jobssystem:getPlayerJob')
AddEventHandler('jobssystem:getPlayerJob', function()
TriggerEvent('es:getPlayerFromId', source, function(user)
local player = user.identifier
local executed_query = MySQL:executeQuery("SELECT j1.`tag` AS job_tag, j1.`libelle` AS job_libelle, j1.`is_legal` AS is_legal, c1.`x` AS entreprise_x, c1.`y` AS entreprise_y, c1.`z` AS entreprise_z, c2.`x` AS stuff_x, c2.`y` AS stuff_y, c2.`z` AS stuff_z, c3.`x` AS vehicule_x, c3.`y` AS vehicule_y, c3.`z` AS vehicule_z FROM jobs j1 INNER JOIN users ON users.`job_id` = j1.id INNER JOIN coords c1 ON j1.`entreprise_coord_id` = c1.id INNER JOIN coords c2 ON j1.`stuff_coord_id` = c2.id INNER JOIN coords c3 ON j1.`vehicule_coord_id` = c3.id WHERE users.identifier = '@userId'", {['@userId'] = player})
local result = MySQL:getResults(executed_query, {'job_tag', 'job_libelle', 'is_legal', 'entreprise_x', 'entreprise_y', 'entreprise_z', 'stuff_x', 'stuff_y', 'stuff_z', 'vehicule_x', 'vehicule_y', 'vehicule_z'})
if(result) then
playerJob = result
end
TriggerClientEvent("cli:getPlayerJob", source, playerJob)
end)
end)
If I execute it on MySQL it returns exactly what I want :
But, in my client file, I can’t access this field.
PLAYERJOB = {}
RegisterNetEvent("cli:getPlayerJob")
AddEventHandler("cli:getPlayerJob", function(job)
PLAYERJOB = job
end)
When I debug what’s inside PLAYERJOB it says :
I tried to display with this methods :
PLAYERJOB[1].job_libelle
PLAYERJOB.job_libelle
for _, item in pairs(PLAYERJOB) do
DisplayDebug(item.job_libelle)
end
None of this is working. Am I missing something ?
My MySQL request should return only one element and I would like to be able to access it like an objet : myObject.myProperty
Is there a way to do it ?
Thank’s in advance for your help !
Leor,