mysql error

Started by King, Jun 13, 2016, 04:23 PM

Previous topic - Next topic

King

local q = mysql_query( sqliteDB, "SELECT * FROM Cars WHERE ID='" + vehicle.ID + "'" );
  MessagePlayer( msg.I + " You have entered ID: " + vehicle.ID + "  Cost: " + mysql_fetch_assoc( q )["Cost"] + "  Owner : " + mysql_fetch_assoc( q )["Owner"] + "  Share : " + mysql_fetch_assoc( q )["Share"] , player );


Error :
AN ERROR HAS OCCURED [the index 'Owner' does not exist]

Mysql table : CREATE TABLE Cars ( ID NUMERIC, Cost VARCHAR(25), Owner TEXT, Share TEXT )

Here , cost works fine but giving error when it checks owner.

Thijn

That's because once you call mysql_fetch_assoc it moves the pointer to the next row, which doesn't exist.
Store the fetched row in a variable and get your properties from there:

local q = mysql_query( sqliteDB, "SELECT * FROM Cars WHERE ID='" + vehicle.ID + "'" );
local result = mysql_fetch_assoc( q );
if ( result ) {
  MessagePlayer( msg.I + " You have entered ID: " + vehicle.ID + "  Cost: " + result["Cost"] + "  Owner : " + result["Owner"] + "  Share : " + result["Share"] , player );
}