MySQL Question. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Question. (
/showthread.php?tid=480296)
MySQL Question. -
Dokins - 09.12.2013
Say I deleted a vehicle (which is saved in mysql) and I want to keep the vehicle id's relevant.
i.e If I delete the vehicle and the vehicle id = 5, the next vehicle I create will be ID 6, unless I change that in operations.
How do I delete the vehicle and set the 'free' id to 5. So if I create a new vehicle it changes back to 5.
Re: MySQL Question. -
Jefff - 09.12.2013
I dont know how your databse looks but if you delete vehicle set for example accountid to 0 and rest fields in table for id 5
then if a player create new use select id from table where accountid = 0 limit 1
pawn Код:
if(mysql_num_rows() == 0)
{
free result
insert next id so 6
}else{
get field 0
free result
new vehicleid = CreateVehicle(...
VehicleData[vehicleid][sql_id] = id_from_table;
}
Re: MySQL Question. -
Dokins - 09.12.2013
Quote:
Originally Posted by Jefff
I dont know how your databse looks but if you delete vehicle set for example accountid to 0 and rest fields in table for id 5
then if a player create new use select id from table where accountid = 0 limit 1
pawn Код:
if(mysql_num_rows() == 0) { free result insert next id so 6 }else{ get field 0 free result new vehicleid = CreateVehicle(... VehicleData[vehicleid][sql_id] = id_from_table; }
|
I don't quite understand.
I mean ONE specific vehicle.
Re: MySQL Question. -
Tayab - 09.12.2013
What I think might work is when you add a vehicle in the database, get the maximum value of the id and then subtract it my 1. Again, I am not 100% sure if that might do it because you might have set your id value to AUTO_INCREMENT.
Re: MySQL Question. -
Dokins - 09.12.2013
Quote:
Originally Posted by Tayab
What I think might work is when you add a vehicle in the database, get the maximum value of the id and then subtract it my 1. Again, I am not 100% sure if that might do it because you might have set your id value to AUTO_INCREMENT.
|
Hmm that's the right idea, that has made me think. I think what it is, is...
I save the deleted vehicle's ID, then when the next vehicle is created it uses that?
Re: MySQL Question. -
Tayab - 09.12.2013
Either that or what I was thinking is that when creating a car, query the max value of the id field and +1 to it and that should be your id for the car you create.