Help with loading id's with gaps between them
#1

Hello, i got a problem loading my Car IDS from the database. Well its working fine but at this moment it has a dissability to be abled to sell anything. The problem is there is id 1,2,3,5 in the database but the server loads it like this 1,2,3,4 while i want to skip 4 and go to 5. How would i go around to do that? Underneath here is my code:
pawn Код:
forward OnCarIDsLoad();
public OnCarIDsLoad()
{
    new rows, fields;
    cache_get_data(rows, fields, Handle);
   
    new i = 0;
    while( rows > i < 10000)
    {
        VehicleLoad[i] = true;
        printf("Car %d created", i);
        i++;
    }
    print("Loading finished");
    return 1;
}
Here's a picture of the database
Uploaded with ImageShack.us
Reply
#2

I had this problem too. Keep in mind that array indexes start from 0, and database indexes start from 1. I had additional field in enumerator called dbID, which held the database id of record. Iterators are really handy if you don't know how much records are loaded. Also remember that you shouldn't waste any memory, so if you skip some key in array, you are wasting enum size*cell bytes of memory.
Reply
#3

But how would i skip the row if it was empty? it now just loads the next one as the WRONG id
Reply
#4

What kind of field do you use for ID? It doesn't look like SERIAL (int(11) auto increment unique primary key), because 0 isn't a valid ID.
I strongly suggest that you don't rely on database id being mapped to array index.

Anyway, answer to your original question:

pawn Код:
forward OnCarIDsLoad();
public OnCarIDsLoad()
{
    new rows, fields;
    cache_get_data(rows, fields, Handle);
   
    new i = 0, realid = 0;
    while(rows > i < 10000)
    {
        realid = cache_get_row_int(i, 0, Handle);
        VehicleLoad[realid] = true;
        printf("Car %d created", realid);
        i++;
    }
    print("Loading finished");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)