Little MySQL help
#1

Hello guys! As you can see in the title I need a little help with MySQL! I have a gang system with gang IDs. When I create the gang the gang ID's is the number of rows +1, but I have a little problem. When I try to delete the gang and if the gang id is 2 and gang id 3,4,5 and etc. exists there is a something like hole with number 2 and when I try again to create a gang it duplicate the last number, like I have 2 gangs with ID 5.
So I want when I delete the gang all of the numbers which are bigger than the ID of the gang I removed to get -1 value. I tried it, but it didn't work! Can you show me an example code please!
Thanks! +1 REP if you help me!

SORRY FOR BAD ENGLISH, I HOPE YOU UNDERSTOOD ME!
Reply
#2

We aren't magicians who can guess your code - so post it. Post your table code, and your commands.
Reply
#3

Okay!
PHP код:
mysql_format(MyMySQLquerysizeof(query), "DELETE FROM `gangs` WHERE `ID` = '%d'"g); 
g is the player's gang ID
Gang table doesn't matter. I need just an example with code. I will change the name of the table and what else!
Reply
#4

EDITED! I DID IT!
Here is the code:

PHP код:
for(new 10cache_num_rows(); i++, r++)
        {
            new 
ID;
            
cache_get_value_name_int(r"ID"ID);
            if(
ID g)
            {
                
mysql_format(MyMySQLquerysizeof(query), "UPDATE `gangs` SET `ID` = '%d' WHERE `ID` > '%d'"ID-1g);
                
mysql_query(MyMySQLquery);
            }
        } 
Reply
#5

This is NOT how SQL is supposed to be USED.

There's a REASON why you use AUTO INCREMENT in the column for IDs. If you're changing IDs whenever you delete a field or make a new one just because that's necessary for your system to work then your code is flawed.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)