MySQL Question.
#1

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.
Reply
#2

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;
}
Reply
#3

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.
Reply
#4

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.
Reply
#5

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?
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)