Problem rank
#1

How to replace it with the newer BlueG MySQL ?
Code:
stock LoadRank()
{
    new query[512], id, type, ranks[256], rank[MAX_RANK][MAX_RANK_LEN];
    mysql_query("SELECT * FROM `rankname`");
    mysql_store_result();

    while(mysql_fetch_row_format(query, "|"))
    {
        sscanf(query, "p<|>dds[256]", id, type, ranks);
        sscanf(ranks, "p<,>A<s[25]>()[10]", rank);

        if(type == 1)
        {
            for(new i = 0; i < MAX_RANK; i++)
            {
                if(strlen(rank[i]) > 1) format(FracRank[id][i], 25, "%s", rank[i]);
            }
        }
    }
    mysql_free_result();
    print("Ranks were read");
}
Reply
#2

There's an example how to use it - https://sampforum.blast.hk/showthread.php?tid=627520

Place where calling LoadRank function:
Code:
mysql_format(MySQL, query, sizeof(query), "SELECT * FROM rankname");
mysql_tquery(MySQL, query, "LoadRank", #, #);
public LoadRank();
Code:
forward LoadRank();
public LoadRank()
{
	new results = cache_num_rows();
	if(results > 0)	// if there is any results
	{
		for(new i = 0; i < results; i++)
		{
			cache_get_value(i, "name of variable in database", yourStringVariable, size of string); // string
			cache_get_value_int(i, "name of variable in database", yourIntVariable); // saving value to the variable
			cache_get_value_float(i, "name of variable in database", yourFloatVariable); // saving value to the variable
		}
		print("Ranks were read");
	}
	else 	// There is no results
	{

	}
	return 1;
}
Reply
#3

Thank you!!
Reply
#4

Why do not the ranks want to load?
Code:
CMD:loadallrank(playerid, params[])
{
    if(PlayerInfo[playerid][Wlasciciel] == 0) return 1;
    SendClientMessage(playerid, -1, "Loading ranks.");

    LoadAllRank();

    new str[32];
    for(new id = 1; id < MAX_FRAC; id++)
    {
        if(strlen(FractionNames[id]) > 1)
        {
            format(str, 32, "%s", FractionNames[id]);
            SendClientMessage(playerid, -1, str);
            for(new i = 0; i < MAX_RANG; i++)
            {
                if(strlen(FracRang[id][i]) > 1)
                {
                    SendClientMessage(playerid, -1, FracRang[id][i]);
                }
            }
        }
    }
    SendClientMessage(playerid, -1, "OK");
    return 1;
}

forward LoadAllRank();
public LoadAllRank()
{
	new query[1500];
	mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `namerank`");
	mysql_tquery(g_SQL, query, "LoadRank");
	return 1;
}

forward LoadRank();
public LoadRank()
{
	new id, type, ranks[256];

	new results = cache_num_rows();
	if(results > 0)
	{
		for(new i = 0; i < results; i++)
		{
			cache_get_value_int(i, "ID", id);
			cache_get_value_int(i, "type", type);
			cache_get_value_name(i, "ranks", ranks, MAX_RANG_LEN);
		}
		print("Ranks were read");
	}
	else
	{

	}
	return 1;
}
In the database I have this saved
ID: 1
ranks: -, -, -, -, -, -, Chief,
type: 1
Reply
#5

What kind of variable is this - "ranks"? If it stores multiple ranks then you're not implementing code properly. Code above included loop refers to every rank in the database which you want to load. I assume that you don't want to load everyting into one string. You've loaded them and put in the variable like id, type and "ranks" but what are you doing next? Is this all? If so, in this case every loop owerwrites it.

I can't see your database tree or global variables if there are any. Also! Your variables in the function are local, did u noticed it?
Reply
#6

I do not know if this is it
Code:
CMD:saveranks(playerid, params[])
{
	for(new i=0;i<MAX_FRAC;i++)
    {
        if(RANG_ApplyChanges[0][i]) EDIT_SaveRanks(0, i);
    }
    for(new i=0;i<MAX_ORG;i++)
    {
        if(RANG_ApplyChanges[1][i]) EDIT_SaveRanks(1, i);
    }
    SendClientMessage(playerid, -1, "Save ranks!");
    return 1;
}

stock EDIT_SaveRanks(typ, uid)
{
    new lStr[256], query[512];

    for(new i = 0; i < MAX_RANG; i++)
    {
        if(strlen((typ == 0) ? (FracRang[uid][i]) : (FamRang[uid][i])) < 2)
        {
            format(lStr, 256, "%s-, ", lStr);
        }
        else
        {
            format(lStr, 256, "%s%s, ", lStr, (typ == 0) ? (FracRang[uid][i]) : (FamRang[uid][i]));
        }
    }
    strdel(lStr, strlen(lStr)-2, strlen(lStr));

    format(query, 512, "SELECT `ID` FROM namerank WHERE `ID` = '%d' AND `type` = '%d'", uid, type+1);
    mysql_query(g_SQL, query);

    if(cache_num_rows() > 0)
    {
        format(query, 512, "UPDATE namerank SET ranks = '%s' WHERE `ID` = '%d' AND `type` = '%d'", lStr, uid, type+1);
    }
    else
    {
        format(query, 512, "INSERT INTO namerank (ranks, ID, type) VALUES ('%s', '%d', '%d')", lStr, uid, type+1);
    }
    mysql_query(g_SQL, query);
    RANG_ApplyChanges[type][uid] = false;
    return 1;
}
Old code
Code:
new query[512], id, type, ranks[256], rank[MAX_RANG][MAX_RANG_LEN];
Reply
#7

No, I did not notice. "ranks" are all ranks, eg Cadet, Police Officer, Police II. "rank" is one rank, eg Cadet.
Reply
#8

Edit: below code id broken. Try to use your first code except included new functions. For example this line
sscanf(ranks, "p<,>A<s[25]>()[10]", rank); You need to apply already logical moves

Code:
forward LoadRank();
public LoadRank()
{
	new id, type, ranks[256], rank[MAX_RANK][MAX_RANK_LEN];

	new results = cache_num_rows();
	if(results > 0)
	{
		for(new i = 0; i < results; i++)
		{
			cache_get_value_int(i, "ID", id);
			cache_get_value_int(i, "type", type);
			cache_get_value_name(i, "ranks", ranks, MAX_RANG_LEN);

                     if(type == 1)
                     {
                           for(new j = 0; j < MAX_RANK; j++)
                           {
                                 if(strlen(rank[j]) > 1) format(FracRank[id][j], 25, "%s", rank[j]);
                           }
                     }
		}
		print("Ranks were read");
	}
	else
	{

	}
	return 1;
}
Reply
#9

I added and works! Thanks!!
Code:
sscanf(query, "p<|>dds[256]", id, type, ranks);
sscanf(ranks, "p<,>A<s[25]>()[10]", rank);
As to whether it will be needed?
sscanf(query, "p<|>dds[256]", id, type, ranks);

EDIT: One more problem
Ranks in the database have been recorded.
ranks: R000, R111, R222, R333, R444, R555, R666, R777, R888, R999

All ranks have not been loaded, I do not know why.
R000, R111, R222, R333 and the rest do not. Why?
Reply
#10

The database is 0-9 ranks. Loaded ranks 0-5 why?
Code:
forward LoadRank();
public LoadRank()
{
	new query[500], id, type, ranks[256], rank[MAX_RANG][MAX_RANG_LEN];

	new results = cache_num_rows();

	if(results > 0)
	{
		for(new i = 0; i < results; i++)
		{
			cache_get_value_int(i, "ID", id);
			cache_get_value_int(i, "type", type);
			cache_get_value_name(i, "ranks", ranks, MAX_RANG_LEN);

			sscanf(query, "p<|>dds[256]", id, type, ranks);
			sscanf(ranks, "p<,>A<s[25]>()[10]", rank);

            if(type == 1)
            {
                for(new j = 0; j < MAX_RANG; j++)
                {
                    if(strlen(rank[j]) > 1) format(FracRang[id][j], 25, "%s", rank[j]);
                }
            }
		}
		print("Ranks were read");
	}
	else
	{

	}
	return 1;
}
Reply
#11

Can you please show us your MySQL table structure here?
Reply
#12

I do not know if this is a MySQL table.
Код:
TableRank()
{
	new query[500];
	strcat(query, "CREATE TABLE IF NOT EXISTS `namerank` (");
	strcat(query, "`ID` INT(11) NOT NULL AUTO_INCREMENT,");
	strcat(query, "`type` INT(11) NOT NULL,");
	strcat(query, "`ranks` VARCHAR(256) NOT NULL,");
	strcat(query, "PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`))");
	mysql_tquery(g_SQL, query);
	return 1;
}
EDIT:
Reply
#13

@REF
Reply
#14

Thanks!! fix rank
Код:
cache_get_value_name(i, "ranks", ranks, 1000);
Reply
#15

Oh no. Don't do this. This is not what MySQL is made for!! You should take a look at Vince's tutorial about "weapon saving" and database saving. Why these? Because they use an amazing feature of MySQL and that is unique and foreign keys.
Reply
#16

Thank you. I will read about it later
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)