Loop problem
#5

You send too many queries.
PHP код:
mysql_format(DatabaseDB_Querysizeof(DB_Query),"INSERT INTO `RANKS` (`ID`) VALUES ('%d')",listitem+1);
mysql_tquery(DatabaseDB_Query);
for(new 
iMAX_FACTIONS_DIVSi++)
{
    for(new 
jMAX_FACTIONS_RANKj++)
    {
        
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `RANKS` SET `D%dR%d`='Undefined' WHERE `ID`='%d'"i+1,j,listitem+1);
        
mysql_query(DatabaseDB_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(DatabaseDB_Querysizeof(DB_Query),
        
"INSERT INTO `RANKS` VALUES ('%d','Undefined','Undefined',..)",
        
listitem+1);
mysql_tquery(DatabaseDB_Query); 
But if you don't know how many column you have you can do this:
PHP код:
new DB_Query[500];
mysql_format(DatabaseDB_Querysizeof(DB_Query),"INSERT INTO `RANKS` (`ID`) VALUES ('%d'",listitem+1);
for(new 
iMAX_FACTIONS_DIVS*MAX_FACTIONS_RANKki++)
    
strcat(DB_Query",'Undefined'");
strcat(DB_Query")");
mysql_tquery(DatabaseDB_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(DatabaseDB_Querysizeof(DB_Query),"INSERT INTO `divisions` VALUES ('%d'"listitem+1);
for(new 
xMAX_FACTIONS_DIVSx++)
    
strcat(DB_Query",'Undefined'");
strcat(DB_Query")");
mysql_tquery(DatabaseDB_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 
iMAX_FACTIONS_DIVSi++)
{
    for(new 
jMAX_FACTIONS_RANKj++)
    {
        if(
|| jstrcat(DB_Query",");
        
format(strsizeof(str), "('%i','%i','%i')"listitem+1i+1j);
                
strcat(DB_Querystr);
    }
}
mysql_tquery(DatabaseDB_Query);
/* divisions structure:  ID | Division | Text  */
new str[40], DB_Query[500] = "INSERT INTO 'divisions' (ID,Division) VALUES ";
for(new 
xMAX_FACTIONS_DIVSx++)
{
    if(
xstrcat(DB_Query",");
    
format(strsizeof(str), "('%i','%i')"listitem+1x+1);
        
strcat(DB_Querystr);
}
mysql_tquery(DatabaseDB_Query); 
Reply


Messages In This Thread
Loop problem - by Nru - 16.06.2018, 07:16
Re: Loop problem - by Calisthenics - 16.06.2018, 08:20
Re: Loop problem - by Nru - 16.06.2018, 08:39
Re: Loop problem - by jlalt - 16.06.2018, 09:53
Re: Loop problem - by GaByM - 17.06.2018, 14:02

Forum Jump:


Users browsing this thread: 1 Guest(s)