SA-MP Forums Archive
Little MySQL help - 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: Little MySQL help (/showthread.php?tid=662187)



Little MySQL help - Kraeror - 25.12.2018

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!


Re: Little MySQL help - Logic_ - 25.12.2018

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


Re: Little MySQL help - Kraeror - 25.12.2018

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!


Re: Little MySQL help - Kraeror - 25.12.2018

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);
            }
        } 



Re: Little MySQL help - Logic_ - 25.12.2018

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.