Jump to content

sql table with gridlist


mjau

Recommended Posts

Posted

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?

n-560x95_E60303_FFFFFF_030303_FF0303.png
Posted

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 

?

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

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 ?

n-560x95_E60303_FFFFFF_030303_FF0303.png
Posted

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.

EPT Team Server Development: 0%

Learning C++ | C++ is amazing xD

Posted

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

n-560x95_E60303_FFFFFF_030303_FF0303.png
Posted

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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

n-560x95_E60303_FFFFFF_030303_FF0303.png
Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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