Trevit Posted January 30, 2011 Share Posted January 30, 2011 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
12p Posted January 30, 2011 Share Posted January 30, 2011 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
Trevit Posted January 30, 2011 Author Share Posted January 30, 2011 Error: attempt to index field 'i' (a nil value) Link to comment
FFS-Racing Posted January 30, 2011 Share Posted January 30, 2011 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
Trevit Posted January 30, 2011 Author Share Posted January 30, 2011 Now it just says bad argument and infinite running script. Link to comment
SDK Posted January 30, 2011 Share Posted January 30, 2011 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
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