Jump to content

Getting data from table


Mann56

Recommended Posts

Hey guys,

I've been working on a vehicle-system and i want to retrieve an item from a table, which i don't know how to do...

function(thePlayer) 
        local owner = getAccountName(getPlayerAccount(thePlayer)) 
        local check = dbPoll(dbQuery(connection,"SELECT Id FROM purchasedCars WHERE Owner = ? AND Slot = ?",owner,1),-1) 
        if #check == 1 then 
            -- I want to get the model id present inside table in a variable 'id' here 
            local x,y,z = getElementPosition(thePlayer) 
            createVehicle(id,x+5,y+5,z) 
        end 
end 

Some help would be appreciated. I just want the model id from the table 'check' , table.concat didn't work...

Link to comment

Well i did :

function(thePlayer) 
        local owner = getAccountName(getPlayerAccount(thePlayer)) 
        local check = dbPoll(dbQuery(connection,"SELECT Id FROM purchasedCars WHERE Owner = ? AND Slot = ?",owner,1),-1) 
        if #check == 1 then 
             
            local id = table.concat(check) 
            outputChatBox(id) 
            local x,y,z = getElementPosition(thePlayer) 
            createVehicle(id,x+5,y+5,z) 
        end 
end 

it Said:

Invalid value (table) at index 1 in table for 'concat'

Link to comment

Try that,

function(thePlayer) 
    local owner = getAccountName(getPlayerAccount(thePlayer)) 
    local check = dbPoll(dbQuery(connection,"SELECT Id FROM purchasedCars WHERE Owner = ? AND Slot = ?",tostring(owner),1),-1) 
    if type(check) == "table" and #check > 0  then 
        local id = tostring(check[1]["Id"]) 
        local x,y,z = getElementPosition(thePlayer) 
        createVehicle(id,x+5,y+5,z) 
    end 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...