mjau Posted March 17, 2012 Posted March 17, 2012 if i return a table like this function getOwnedCars(accountName) local vehicles = executeSQLSelect("vehicles", "vehicleID", "owner = '"..accountName.."'") return vehicles end how can i get vehicle names from all the id rows in the table and add them to a gridlist?
drk Posted March 17, 2012 Posted March 17, 2012 Maybe local vehicles = executeSQLQuery [[ SELECT vehicleID FROM vehicles WHERE owner = '"..accountName.."' ]] for _, veh in ipairs ( vehicles ) do row = guiGridListAddRow ( yourGridList ) guiGridListSetItemText ( yourGridList, row, column, tostring(veh), false, false ) end ?
mjau Posted March 17, 2012 Author Posted March 17, 2012 ok but if i wanna turn the id into the vehicle name and put that in gridlist how ?
mjau Posted March 17, 2012 Author Posted March 17, 2012 the function is exportes so i can easely send the table to client with triggerclientevent but how can i get all rows in table i selected then trun vehicle id into vehicle name and add to gridlist ?
drk Posted March 17, 2012 Posted March 17, 2012 Maybe: Server-side: function getOwnedCars(accountName) local vehicles = executeSQLQuery [[ SELECT vehicleID FROM vehicles WHERE owner = '" .. accountName .. "' ]] return vehicles end addEventHandler ( "onResourceStart", root, function ( ) triggerClientEvent ( "setOwnedCars", localPlayer, getOwnedCars(getAccountName(getPlayerAccount(source))) ) end ) Client-side: addEvent ( "setOwnedCars", true ) addEventHandler ( "setOwnedCars", root, function ( carList ) for _, vehID in ipairs ( carList ) do guiGridListSetItemText ( yourGridList, row, column, tostring(vehID), false, false ) end end ) not tested. This will only get the vehicle ID from "vehicles" because you are only selecting "vehicleID" column.
Kenix Posted March 17, 2012 Posted March 17, 2012 It's wrong code Draken. kimmis9,Can you explain what you want create?
mjau Posted March 17, 2012 Author Posted March 17, 2012 Sure I am making a SQL system with exported functions to use in scripts later now im making the vehicle storage functions and was going to start creating the vehicle system in another resource wich uses theese exported functions but i need to knopw how to take all rows from the table returned and change the vehicleID wich is in the table to vehiclename then add them to gridlist...
Kenix Posted March 17, 2012 Posted March 17, 2012 Client addEvent ( 'setOwnedCars', true ) --[[ INFO: uGridList - your grid list nColumn - your column number ]] addEventHandler ( 'setOwnedCars', root, function ( tVehicleList ) if tVehicleList then for _, varVehicleId in pairs ( tVehicleList ) do local nRow = guiGridListAddRow( uGridList ) guiGridListSetItemText ( uGridList, nRow, nColumn, tostring( varVehicleId ), false, false ) end end end ) Server addEvent ( 'triggerToClientOwnerCars', true ) function fGetVehicleIds( uPlayer ) if isElement( uPlayer ) then local uAccountPlayer = getPlayerAccount( uPlayer ) if uAccountPlayer and not isGuestAccount( uAccountPlayer ) then local sAccountName = getAccountName( uAccountPlayer ) return executeSQLQuery ( " SELECT vehicleID FROM vehicles WHERE owner = '" .. sAccountName .. "' " ) end return false end return false end addEventHandler ( 'triggerToClientOwnerCars', root, function ( ) triggerClientEvent( 'setOwnedCars', source, fGetVehicleIds( source ) ) end ) Like this
mjau Posted March 17, 2012 Author Posted March 17, 2012 i think you didnt get me right I have one resource called SQL wich i export every sql function i need from and i aleready got that part done then when i create another resource and use the exported function i got the table in that resource too so i dont need help with my SQL part of the script i just need help turning the vehicleIDs from the table i returned to vehicle names and add them as rows in a gridlist...
Castillo Posted March 17, 2012 Posted March 17, 2012 Use getVehicleNameFromModel to get the vehicle name from model.
mjau Posted March 17, 2012 Author Posted March 17, 2012 tnx solidsnake ill try this tomorrow im to tired now ive been watching c++ tutorials all day ...
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