Loop problem
#1

so here is the code
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");*/
                        
}
                    }
                    
mysql_format(DatabaseDB_Querysizeof(DB_Query),"INSERT INTO `divisions` (`ID`) VALUES ('%d')",listitem+1);
                    
mysql_tquery(DatabaseDB_Query);
                    for(new 
xMAX_FACTIONS_DIVSx++)
                    {
                        
format(keysizeof(key),"DIV_%d",x+1);
                        
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `divisions` SET `%s`='Undefined' WHERE `ID`='%d'"key,listitem+1);
                        
mysql_query(DatabaseDB_Query);
                        
/*iGroupDivs[listitem+1][x] = "Undefined";*/
                    




So there's a problem with the loop I guess..
Reply
#2

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
}
Reply
#3

Actually it effected the row but Incomplete
Reply
#4

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(DatabaseDB_Querysizeof(DB_Query), "UPDATE `RANKS` SET `D%dR%d`='Undefined' WHERE `ID`='%d'"i+1,j,listitem+1); 
mysql_tquery(DatabaseDB_Query); 
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)