Jump to content

sql table with gridlist


mjau

Recommended Posts

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?

Link to comment

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 

?

Link to comment

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.

Link to comment

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

Link to comment

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

Link to comment

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

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