Jump to content

Getting data from table


Mann56

Recommended Posts

Posted

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...

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

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'

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

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 

Posted

Thanks Karim, it worked!! So you got the first index under column Id... Thanks i'll keep this method in mind.

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

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...