Hero192 Posted October 2, 2015 Share Posted October 2, 2015 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
t3wz Posted October 2, 2015 Share Posted October 2, 2015 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
TAPL Posted October 2, 2015 Share Posted October 2, 2015 The index of the table isn't numeric, it's the columns name in the sql table. And you should loop the first row in the table only (vehList[1]). Link to comment
Hero192 Posted October 2, 2015 Author Share Posted October 2, 2015 Thanks for TAPL and t3wz worked i followed you both Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now