SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/12/2016, 06:52 AM   #1
SkyFlare
Huge Clucker
 
SkyFlare's Avatar
 
Join Date: Apr 2015
Location: NZ
Posts: 221
Reputation: 43
Default MySQL Not Reading Database as intended.

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();
__________________
Purchasable Scripting Services Available, Inbox me with your Requests.
My Project Progress Tracker
My Work
Link
Information
S-Store System V2 LinkIngame Store in Dialogs
SkyFlare is offline   Reply With Quote
Old 27/12/2016, 08:23 AM   #2
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 872
Reputation: 291
Default Re: MySQL Not Reading Database as intended.

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.
__________________
viva la sa-mp

Last edited by X337; 27/12/2016 at 08:26 AM. Reason: typo
X337 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MySQL] /f(action) bug | Reading a string from the SQL database vIBIENNYx Scripting Help 22 06/09/2012 03:18 PM
MySQL reading from database help Killer#Mummy Scripting Help 5 14/05/2012 01:17 PM
Reading from database ArcherTRP Help Archive 4 28/07/2011 01:59 PM
Reading name from database going wrong. Typhome Help Archive 2 03/05/2011 06:53 PM
MYSQL - Reading data from Database joshAllan Help Archive 4 14/10/2009 11:46 AM


All times are GMT. The time now is 08:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.