Need help with Auto_Increment MYSQL!
#1

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)