SA-MP Forums Archive
Need help with Auto_Increment MYSQL! - 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: Need help with Auto_Increment MYSQL! (/showthread.php?tid=526054)



Need help with Auto_Increment MYSQL! - dieuhanhphuc - 15.07.2014

I'm making a Business MYSQL, but i have problem with the ID of every Business.
The problem is when i delete one Business and create new one, but the ID did'nt replace the old ID, it make a new ID for that business. I use this script but it's not really effective. Help me


PHP код:
for(new i=0i<MAXBIZi++)
{
    
format(query,sizeof(query), "SELECT * FROM business WHERE IDBiz=%d",i);
    new 
rowsfields;
    
cache_get_data(rowsfields);
    if(!
rows)
    {
        
id i;
        break;
    }

P/s: I use MYSQL R33


Re: Need help with Auto_Increment MYSQL! - Vince - 15.07.2014

This is NOT the way to load stuff, that's incredibly inefficient. Get rid of the "where idbiz=" part and load the resultset at once. What do you think the "row" variable is for?

This is also NOT what an auto_increment is for. AI solely exists to uniquely identify each row. You should add a variable to your biz enum to store the SQL id. Then use that variable to update the corresponding row.

So it could end up like this:
Код:
Internal ID | SQL auto_increment
0|1
1|2
2|4
3|5
4|7
5|8
Now if I want to update biz 3, I grab the variable and see that it corresponds with SQL id 5. I use that number to update the corresponding row.


Re: Need help with Auto_Increment MYSQL! - dieuhanhphuc - 15.07.2014

Hmmm...so if i don't use Auto_Increment for ID Biz, how can i get the empty id from SQL?