SA-MP Forums Archive
Loop won't load stuff from database - 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: Loop won't load stuff from database (/showthread.php?tid=550366)



Loop won't load stuff from database - Ox1gEN - 12.12.2014

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.


Re: Loop won't load stuff from database - Lordzy - 12.12.2014

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


Re: Loop won't load stuff from database - PowerPC603 - 12.12.2014

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



Re: Loop won't load stuff from database - Ox1gEN - 12.12.2014

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.