Jump to content

How to return a table


Hero192

Recommended Posts

I stuck on anther problem, i want to return a table from database mysql and show it in GUI (gridlist)

i tried that but won't works maybe i did something wrong , i hope you can correct me!

server side:

function getVehicles(accountname) 
    local query = dbQuery(connection, "SELECT * FROM vehicles_table WHERE username = '".. tostring(accountname) .."'LIMIT 1" ) 
    local result = dbPoll(query, -1) 
    if ( type( result ) == "table" and #result == 0 ) or not result then 
         return false 
     else 
         return true 
    end   
end 
  
function vehLists() 
    local account = getPlayerAccount(source) 
    local accountName = getAccountName(account) 
    local vehList = getVehicles(accountName) 
    triggerClientEvent(source,"returnvehList",source,vehList) 
end  
  

client side:

addEvent("returnvehList",true) 
addEventHandler("returnvehList",root, 
function (vehList) 
        guiGridListClear(grid) 
     if guiGetVisible(window) then 
    for index, v in ipairs(vehList) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, 1, v[1], false, false) 
        guiGridListSetItemText(grid, row, 2, v[2], false, false) 
        guiGridListSetItemText(grid, row, 3, v[3], false, false) 
        guiGridListSetItemText(grid, row, 4, v[4], false, false) 
        end 
    end 
end) 

Link to comment

getVehicles is returning a boolean so you don't have any table in the vehLists function.

function getVehicles(accountname) 
    local query = dbQuery(connection, "SELECT * FROM vehicles_table WHERE username = '".. tostring(accountname) .."'LIMIT 1" ) 
    local result = dbPoll(query, -1) 
    if type(result) == "table" then 
        return result 
    else 
        return {} 
    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...