Jump to content

Loop for Cars


Trevit

Recommended Posts

Hi,

I want to load the carinformation from the mysql-table, but there is something wrong with "createVehicle". I hope you can help me.

  
function carspawn ( ) 
    handler = mysql_connect("localhost", "table", "pass", "user") 
    cars = mysql_query(handler, "SELECT * FROM vehicles" ) 
    pCars = mysql_fetch_row( cars ) 
     
    for i, cars in pairs (pCars) do 
        createVehicle( cars[i].model, cars[i].posx, cars[i].posy, cars[i].posz ) 
    end 
     
    if (not cars) then 
         outputDebugString("Error executing the query: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) 
    else 
        mysql_free_result(cars) 
    end 
end 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), carspawn ) 
  

Link to comment

Try this:

  
function carspawn ( ) 
    handler = mysql_connect("localhost", "table", "pass", "user") 
    cars = mysql_query(handler, "SELECT * FROM vehicles" ) 
    pCars = mysql_fetch_row( cars ) 
     
    for i, cars in pairs (pCars) do 
        createVehicle( cars.i[model], cars.i[posx], cars.i[posy], cars.i[posz] ) 
    end 
     
    if (not cars) then 
         outputDebugString("Error executing the query: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) 
    else 
        mysql_free_result(cars) 
    end 
end 
  
carspawn() 
  

Link to comment
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
 function ( ) 
    handler = mysql_connect("localhost", "table", "pass", "user") 
    cars = mysql_query(handler, "SELECT * FROM vehicles" ) 
   
    if cars then 
        pCars = mysql_fetch_row( cars ) 
            while pCars do 
                createVehicle( pCars.model, pCars.posx, pCars.posy, pCars.posz ) 
            end 
        mysql_free_result(cars) 
    else 
         outputDebugString("Error executing the query: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) 
  
    end 
end 
) 

Link to comment

Where did that bad argument error happen? Try this, not sure if it'll work:

addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
    handler = mysql_connect("localhost", "table", "pass", "user") 
    cars = mysql_query(handler, "SELECT * FROM vehicles" ) 
   
    if cars then 
        pCars = mysql_fetch_row( cars ) 
        while pCars do 
            createVehicle( pCars.model, pCars.posx, pCars.posy, pCars.posz ) 
            pCars = mysql_fetch_row( cars ) 
        end 
        mysql_free_result(cars) 
    else 
         outputDebugString("Error executing the query: (" .. mysql_errno(handler) .. ") " .. mysql_error(handler)) 
    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...