Possible to find which ID was created MySQL INSERT?
#1

Okay, so what I'm trying to do, for arguments sake is:

When a vehicle is INSERTED into the 'vehicles' table, retrieve the ID from the inserted row to save to a variable?

pawn Код:
mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[i][vModel], vInfo[i][vPosX], vInfo[i][vPosY], vInfo[i][vPosZ], vInfo[i][vAngle], vInfo[i][vColour1], vInfo[i][vColour2]);
            mysql_tquery(mysql, qString, "", "");

Also, if someone who has knowledge in this area of scripting could PM me with their skype name, it'd be rather handy as I have a few more questions just to verify my methods and whether they can be done easier... As it doesn't seem fit for me to create new threads each time I have a question! Haha.
Reply
#2

Does the table contain an auto_increment field? If so, create a callback and call cache_insert_id() or mysql_insert_id().
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Does the table contain an auto_increment field? If so, create a callback and call cache_insert_id() or mysql_insert_id().
Again.. simple.. I'd used it before and forgot about it... Thanks :l... Gave you some rep.
Reply
#4

pawn Код:
mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[i][vModel], vInfo[i][vPosX], vInfo[i][vPosY], vInfo[i][vPosZ], vInfo[i][Ale], vInfo[i][vColour1], vInfo[i][vColour2]);
            mysql_tquery(mysql, qString, "", "");
And this?
Reply
#5

Quote:
Originally Posted by Roam
Посмотреть сообщение
pawn Код:
mysql_format(mysql, qString, sizeof(qString), "INSERT INTO `vehicles` (`Model`, `posX`, `posY`, `posZ`, `Angle`, `Colour1`, `Colour2`) VALUES ('%i', '%f', '%f', '%f', '%f', '%i', '%i')", vInfo[i][vModel], vInfo[i][vPosX], vInfo[i][vPosY], vInfo[i][vPosZ], vInfo[i][Ale], vInfo[i][vColour1], vInfo[i][vColour2]);
            mysql_tquery(mysql, qString, "", "");
And this?
What do you mean?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)