17.06.2018, 14:02
You send too many queries.
This can easely become
But if you don't know how many column you have you can do this:
You send only one query which is faster for both your SAMP server and your MySQL db server.
Same thing apply to next part:
(You also can set default values for this columns to 'Undefined')
BUT!
If I were you I'd change the table structure so this:
Now each name is on a different row. You can insert multiple rows in the same table by using this:
So this combined with what I already said becomes:
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");*/
}
}
PHP код:
mysql_format(Database, DB_Query, sizeof(DB_Query),
"INSERT INTO `RANKS` VALUES ('%d','Undefined','Undefined',..)",
listitem+1);
mysql_tquery(Database, DB_Query);
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);
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);
BUT!
If I were you I'd change the table structure so this:
PHP код:
ID | Division | Rank | Text
PHP код:
"INSERT INTO 'RANKS' VALUES ('%i','%i','%i','Undefined'),('%i','%i','%i','Undefined'),('%i','%i','%i','Undefined')"
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);