Loop won't load stuff from database
#1

Well, I am back after a long break and learning some other programming languages.
I've decided to continue PAWN because it's really fun, so.. I've forgotten some stuff.

I've been told how to do this like alot of time ago but I forgot it, I attempted to re-do it just in another scenario and nothing worked, same problem I encountered in the past.

Here's the code, thanks for anyone assisting.


pawn Код:
public OnFilterScriptInit()
{
    mysql_log(LOG_ALL);
    print("\n--------------------------------------");
    print(" ************************************");
    print("--------------------------------------\n");
    dbconnect(SQL_DB);
    return 1;
}

forward dbconnect(db);
public dbconnect(db) {

    if(db == SQL_DB) {
       
        dbHandle = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_DATABASE, MySQL_PASSWORD);
        if(mysql_errno() != 0) {
            print("Failed connection to database -- Shutting down.");
            SendRconCommand("exit");
        }
        else
        {
            print("Successful connection to database -- Continue ~~~");
        }
        LoadDSquery();
    }
}

stock LoadDSquery() {
    mysql_tquery(dbHandle, "SELECT * FROM `dealerships`", "LoadDEALERSHIPS");
    return 1;
}

forward loadDEALERSHIPS();
public loadDEALERSHIPS() {

    for(new i = 0 ; i < cache_num_rows(dbHandle) ; i++) {

        DS[i][DsID] = cache_get_field_content_int(i, "DsID", dbHandle);
        DS[i][DsLocX] = cache_get_field_content_float(i, "DsLocX", dbHandle);
        DS[i][DsLocY] = cache_get_field_content_float(i, "DsLocY", dbHandle);
        DS[i][DsLocZ] = cache_get_field_content_float(i, "DsLocZ", dbHandle);
        DS[i][DsIcon] = cache_get_field_content_int(i, "DsIcon", dbHandle);
        DS[i][DsSpawned] = cache_get_field_content_int(i, "DsSpawned", dbHandle);


        DsPickups = CreatePickup(1239, 23, DS[i][DsLocX], DS[i][DsLocY], DS[i][DsLocZ], -1);


        DS[i][DsSpawned] = 1;
    }
        printf("Loaded %d DEALERSHIPS", cache_num_rows(dbHandle));
    return 1;
}

I am 99% sure I am doing most of this wrong.
Reply
#2

You mentioned LoadDEALERSHIPS on calling the thread and while forwarding it, it got changed to loadDEALERSHIPS .
Reply
#3

Try this:
pawn Код:
mysql_tquery(dbHandle, "SELECT * FROM `dealerships`", "LoadDEALERSHIPS", ""); // Added the extra ,""
Reply
#4

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
You mentioned LoadDEALERSHIPS on calling the thread and while forwarding it, it got changed to loadDEALERSHIPS .
Sometimes-.. I am just dumb.

Thank you very much


Edit:

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
Try this:
pawn Код:
mysql_tquery(dbHandle, "SELECT * FROM `dealerships`", "LoadDEALERSHIPS", ""); // Added the extra ,""
Correct me if I am wrong but you can use it without another parameter because it's an optional parameter I believe.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)