Loop problem -
Nru - 16.06.2018
so here is the code
PHP код:
mysql_format(Database, DB_Query, sizeof(DB_Query),"INSERT INTO `RANKS` (`ID`) VALUES ('%d')",listitem+1);
mysql_tquery(Database, DB_Query);
for(new i; i < MAX_FACTIONS_DIVS; i++)
{
for(new j; j < MAX_FACTIONS_RANK; j++)
{
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `RANKS` SET `D%dR%d`='Undefined' WHERE `ID`='%d'", i+1,j,listitem+1);
mysql_query(Database, DB_Query);
/*format(key, sizeof(key),"Rank%d",j);
rank = GetRanksEnum(key);
format(iGroupRank[listitem+1][i][rank],128,"Undefined");*/
}
}
mysql_format(Database, DB_Query, sizeof(DB_Query),"INSERT INTO `divisions` (`ID`) VALUES ('%d')",listitem+1);
mysql_tquery(Database, DB_Query);
for(new x; x < MAX_FACTIONS_DIVS; x++)
{
format(key, sizeof(key),"DIV_%d",x+1);
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `divisions` SET `%s`='Undefined' WHERE `ID`='%d'", key,listitem+1);
mysql_query(Database, DB_Query);
/*iGroupDivs[listitem+1][x] = "Undefined";*/
}
So there's a problem with the loop I guess..
Re: Loop problem -
Calisthenics - 16.06.2018
A note: when you send a threaded query (INSERT) and directly send another query which is based on the new row, it will not have effect.
pawn Код:
mysql_format(Database, DB_Query, sizeof(DB_Query),"INSERT INTO `RANKS` (`ID`) VALUES ('%d')",listitem+1);
mysql_tquery(Database, DB_Query, "OnRankInsert", "d", listitem+1);
pawn Код:
forward OnRankInsert(new_faction_rank);
public OnRankInsert(new_faction_rank)
{
// the new row was insert successful, you can execute other queries that use "WHERE ID=%d" here
}
Re: Loop problem -
Nru - 16.06.2018
Actually it effected the row but Incomplete
Re: Loop problem -
jlalt - 16.06.2018
You're executing a threaded query first _tquery then executing a non threaded one, _query.
either change both to non-threaded or threaded.
PHP код:
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `RANKS` SET `D%dR%d`='Undefined' WHERE `ID`='%d'", i+1,j,listitem+1);
mysql_tquery(Database, DB_Query);
Re: Loop problem -
GaByM - 17.06.2018
You send too many queries.
PHP код:
mysql_format(Database, DB_Query, sizeof(DB_Query),"INSERT INTO `RANKS` (`ID`) VALUES ('%d')",listitem+1);
mysql_tquery(Database, DB_Query);
for(new i; i < MAX_FACTIONS_DIVS; i++)
{
for(new j; j < MAX_FACTIONS_RANK; j++)
{
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `RANKS` SET `D%dR%d`='Undefined' WHERE `ID`='%d'", i+1,j,listitem+1);
mysql_query(Database, DB_Query);
/*format(key, sizeof(key),"Rank%d",j);
rank = GetRanksEnum(key);
format(iGroupRank[listitem+1][i][rank],128,"Undefined");*/
}
}
This can easely become
PHP код:
mysql_format(Database, DB_Query, sizeof(DB_Query),
"INSERT INTO `RANKS` VALUES ('%d','Undefined','Undefined',..)",
listitem+1);
mysql_tquery(Database, DB_Query);
But if you don't know how many column you have you can do this:
PHP код:
new DB_Query[500];
mysql_format(Database, DB_Query, sizeof(DB_Query),"INSERT INTO `RANKS` (`ID`) VALUES ('%d'",listitem+1);
for(new i, j = MAX_FACTIONS_DIVS*MAX_FACTIONS_RANK; i < k; i++)
strcat(DB_Query, ",'Undefined'");
strcat(DB_Query, ")");
mysql_tquery(Database, DB_Query);
You send only one query which is faster for both your SAMP server and your MySQL db server.
Same thing apply to next part:
PHP код:
new DB_Query[200];
mysql_format(Database, DB_Query, sizeof(DB_Query),"INSERT INTO `divisions` VALUES ('%d'", listitem+1);
for(new x; x < MAX_FACTIONS_DIVS; x++)
strcat(DB_Query, ",'Undefined'");
strcat(DB_Query, ")");
mysql_tquery(Database, DB_Query);
(You also can set default values for this columns to 'Undefined')
BUT!
If I were you I'd change the table structure so this:
PHP код:
ID | Division | Rank | Text
Now each name is on a different row. You can insert multiple rows in the same table by using this:
PHP код:
"INSERT INTO 'RANKS' VALUES ('%i','%i','%i','Undefined'),('%i','%i','%i','Undefined'),('%i','%i','%i','Undefined')"
So this combined with what I already said becomes:
PHP код:
new str[40], DB_Query[500] = "INSERT INTO 'RANKS' (ID,Division,Rank) VALUES ";
for(new i; i < MAX_FACTIONS_DIVS; i++)
{
for(new j; j < MAX_FACTIONS_RANK; j++)
{
if(i || j) strcat(DB_Query, ",");
format(str, sizeof(str), "('%i','%i','%i')", listitem+1, i+1, j);
strcat(DB_Query, str);
}
}
mysql_tquery(Database, DB_Query);
/* divisions structure: ID | Division | Text */
new str[40], DB_Query[500] = "INSERT INTO 'divisions' (ID,Division) VALUES ";
for(new x; x < MAX_FACTIONS_DIVS; x++)
{
if(x) strcat(DB_Query, ",");
format(str, sizeof(str), "('%i','%i')", listitem+1, x+1);
strcat(DB_Query, str);
}
mysql_tquery(Database, DB_Query);