Posts: 1,648
Threads: 482
Joined: Jun 2010
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.
Posts: 2,593
Threads: 34
Joined: Dec 2007
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;
}
Posts: 1,648
Threads: 482
Joined: Jun 2010
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.
Posts: 190
Threads: 28
Joined: Jul 2013
Reputation:
0
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.
Posts: 1,648
Threads: 482
Joined: Jun 2010
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?
Posts: 190
Threads: 28
Joined: Jul 2013
Reputation:
0
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.