MySQL Not Reading Database as intended.
#1

MySQL factions database has 5 rows but where it says [] theres supposed to be text there for each one.
for example Row 2-5 is "Empty" but Row 1 is "LSPD".

Code:
[20:38:29] Factions MySQL Database Loading...
[20:38:29] Loading Rows from Factions (Row 1) []
[20:38:30] Loading Rows from Factions (Row 2) []
[20:38:30] Loading Rows from Factions (Row 3) []
[20:38:30] Loading Rows from Factions (Row 4) []
[20:38:30] Loading Rows from Factions (Row 5) []
[20:38:30] Loaded 5 Rows from Factions MySQL Database
here is how the factions are being loaded below
pawn Code:
enum E_FACTIONS
{
    ID,
    Name,
    Empty,
    Cache: Cache_ID
};
new Factions[MAX_FACTIONS][E_FACTIONS];

public LoadFactions()
{
    new loadquery[512], count, EMPTY;
    printf("Factions MySQL Database Loading...");
    for(new i = 1; i < MAX_FACTIONS; i++)
    {
        mysql_format(g_SQL, loadquery, sizeof loadquery, "SELECT * FROM `factions` WHERE `id` = '%d' LIMIT 1", Factions[i][ID]);
        mysql_tquery(g_SQL, loadquery, "OnFactionsLoaded", "d", i);
        Factions[i][ID] = i;
        if(Factions[i][ID] == -1 || Factions[i][ID] == EMPTY)
        {
            printf("ERROR Loading Data from Factions (Row %i) MySQL Database", Factions[i][ID]);
        }
        if(Factions[i][Empty] == 1)
        {
            //format(EmptyString, sizeof(EmptyString),"Empty");
            //printf("(Row %i) [%s]",Factions[i][ID], EmptyString);
        }
        else if(Factions[i][Empty] == 0)
        {
            i = Factions[i][ID];
            printf("Loading Rows from Factions (Row %i) [%s]",Factions[i][ID], Factions[i][Name]);
        }
        count = count +1;
    }
    printf("Loaded %i Rows from Factions MySQL Database", count);
    return 1;
}

public OnFactionsLoaded(i)
{
    if(cache_num_rows() > 0)
    {
        cache_get_value(0, "id", Factions[i][ID], 2);
        cache_get_value(0, "name", Factions[i][Name], 18);
        cache_get_value(0, "empty", Factions[i][Empty], 1);
        Factions[i][Cache_ID] = cache_save();
    }
    else
    {
        //no rows
    }
    return 1;
}
Seems like the loop is working as intended for the factions thats about it I believe, as its not really loading from my database, although from looking at the code it should be, since ongamemodeinit ive got it running through LoadFactions();
Reply
#2

Code:
public LoadFactions()
{
    new loadquery[512], count, EMPTY;
    printf("Factions MySQL Database Loading...");
    for(new i = 1; i < MAX_FACTIONS; i++)
	{
	    mysql_format(g_SQL, loadquery, sizeof loadquery, "SELECT * FROM `factions` WHERE `id` = '%d' LIMIT 1", Factions[i][ID]);
		mysql_tquery(g_SQL, loadquery, "OnFactionsLoaded", "d", i);
	    count++;
	}
	printf("Loaded %i Rows from Factions MySQL Database", count);
	return 1;
}

public OnFactionsLoaded(i)
{
	if(cache_num_rows() > 0)
	{
		cache_get_value(0, "id", Factions[i][ID], 2);
		cache_get_value(0, "name", Factions[i][Name], 18);
		cache_get_value(0, "empty", Factions[i][Empty], 1);
		Factions[i][Cache_ID] = cache_save();
		Factions[i][ID] = i;
	    if(Factions[i][ID] == -1 || Factions[i][ID] == EMPTY)
	    {
	    	printf("ERROR Loading Data from Factions (Row %i) MySQL Database", Factions[i][ID]);
	    }
	    if(Factions[i][Empty] == 1)
	    {
	        //format(EmptyString, sizeof(EmptyString),"Empty");
	    	//printf("(Row %i) [%s]",Factions[i][ID], EmptyString);
	    }
	    else if(Factions[i][Empty] == 0)
	    {
	        i = Factions[i][ID];
     		printf("Loading Rows from Factions (Row %i) [%s]",Factions[i][ID], Factions[i][Name]);
	    }
	}
	else
	{
 		//no rows
	}
	return 1;
}
mysql_tquery is threaded, the code after that function will be called even your query is not yet executed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)