Mysqd ID's
#1

Im having problems with my id's in mysql.

I created dynamic apartment's ingame and everything was good till i had to delete one of them through mysql, i did that and when i created next one the id of it is still goin up by one.

Like

1.
2.
3.
4.
Here i deleted one (it was 5.)
Created new one and its 6.

So my list is now like this

1.
2.
3.
4.
6.

And they buggs with enterances n shit. How can i fix it?
Reply
#2

Then don't use auto-increment for that field. Although if you want to keep them in order, then you'll need to update tha field and subtract 1 from it.

So, if you have:

1
2
3
4
5
6

and you remove the number 4, it'll go:

1
2
3
5
6

Then you can update those rows from that field that the value is greater than the value you deleted.

So it'll do:

"UPDATE ... field_here = %d WHERE field_here = %d", 5-1, 5

Just an example, of course it'll be a variable.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
-
That's not how dynamic systems work though.
--
You could either:
1. Create a global variable and set the entrance ID to either true or false if it exists
pawn Код:
new bool: gValidEntrance[MAX_APTS] = {false, ...};

//when loading, load the Apartment ID:

new ID = cache_get_field_content_int(row, "Apartment_ID");

//then
gValidEntrance[ID] = true;

//whenever you attempt to enter a place:
for(new i = 0; i < MAX_APTS; i++)
{
    if(gValidEntrance[ID] == true)
    {
        //The entrance is now valid, shouldn't bug from now on
    }
}
2. Create a function to get the next empty ID
Reply
#4

What the author wants is if he removed a row from the table, then it wouldn't let the rest rows as it is; for example: 0,1,2,3,6,9

Of course that would happen if he loads with a loop and some parts (those which have been removed) will be empty so the best solution actually is to load all the rows from that table and assign each valid ID to the array but we keep in mind that the index (let's say..) 6 may not be the ID 6.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)