converting unthreaded to threaded.
#2

1. You are performing select query before connection!
2. You can simply do all in one query by just giving a limit of MAX_FACTIONS and load all rows upto it.

pawn Код:
public OnGameModeInit()
{
    SetGameModeText("MySQL - Server");


    mysql_log(LOG_ALL);
    mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
    if(mysql_errno() != 0)
    {
        printf("[MySQL] The connection has failed.");
    }
    else
    {
        printf("[MySQL] The connection was successful.");
    }

    mysql_tquery(mysql, "SELECT * FROM `Factions` LIMIT "#MAX_FACTIONS"", "LoadFactions", "");
    return true;
}

forward LoadFactions();
public LoadFactions()
{
    new count = cache_get_row_count();
    for (new i; i < count; i++)
    {
        Factions[i][Type] = cache_get_field_content_int(i, "Type");
        cache_get_field_content(i, "Name", Factions[i][Name]);
        cache_get_field_content(i, "Rank1", Factions[i][Rank1]);
        cache_get_field_content(i, "Rank2", Factions[i][Rank2]);
        cache_get_field_content(i, "Rank3", Factions[i][Rank3]);
        cache_get_field_content(i, "Rank4", Factions[i][Rank4]);
         cache_get_field_content(i, "Rank5", Factions[i][Rank5]);
    }

    printf("> %d factions have been loaded from the database.", count); // Prints out the information of how many factions created
    return 1;
}
// I am not sure if you want "Factions[i][Type]" or is even in existence
Reply


Messages In This Thread
converting unthreaded to threaded. - by DavidLuango - 31.07.2016, 03:19
Re: converting unthreaded to threaded. - by Gammix - 31.07.2016, 04:41

Forum Jump:


Users browsing this thread: 1 Guest(s)