SA-MP Forums Archive
CMySQLResult::GetRowDataByName() - invalid row index ('0') - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: CMySQLResult::GetRowDataByName() - invalid row index ('0') (/showthread.php?tid=608310)



CMySQLResult::GetRowDataByName() - invalid row index ('0') - Morpheine - 30.05.2016

PHP код:
        mysql_format(SQLgQuerysizeof(gQuery), "SELECT * FROM `friends` WHERE `AddBy` = '%d'"PlayerInfo[playerid][pSQLID]);
        
results mysql_query(SQLgQuery);
        for(new 
icache_get_row_count (); != j; ++i)
        {
            
cache_get_field_content(i"friendName"gString);
            new 
userID GetPlayerID(gString);
            if(
userID != INVALID_PLAYER_IDonf ++;
        }
        
cache_delete(results); 
or
PHP код:
mysql_format(SQLgQuerysizeof(gQuery), "SELECT * FROM `friends` WHERE `AddBy` = '%d' AND `friendID` = '%d'"PlayerInfo[i][pSQLID], PlayerInfo[playerid][pSQLID]);
                
results mysql_query(SQLgQuery);
                
cache_get_field_content(0"AddBy"gString); 
Anyone help me please?


Re: [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0') - Konstantinos - 30.05.2016

If there is no result to return, you will try to retrieve from an invalid row. Check if cache_get_row_count is not 0 before getting the data (I'm referring to the second).


Re: [ERROR] CMySQLResult::GetRowDataByName() - invalid row index ('0') - Morpheine - 30.05.2016

Can you give me an example @Konstantinos?


Re: CMySQLResult::GetRowDataByName() - invalid row index ('0') - Konstantinos - 30.05.2016

If it returns more than 1 row, then use a loop like in the first one.
If it returns only 1 row (which in this case you better add "LIMIT 1" at the end of the query), then:
pawn Код:
if (cache_get_row_count(SQL))
{
    cache_get_field_content(0, "AddBy", gString);
}



Re: CMySQLResult::GetRowDataByName() - invalid row index ('0') - Morpheine - 31.05.2016

Doesn't work.


Re: CMySQLResult::GetRowDataByName() - invalid row index ('0') - jlalt - 31.05.2016

Try this
PHP код:
        mysql_format(SQLgQuerysizeof(gQuery), "SELECT * FROM `friends` WHERE `AddBy` = '%d'"PlayerInfo[playerid][pSQLID]); 
        
results mysql_query(SQLgQuery); 
        for(new 
icache_get_row_count (); j; ++i
        { 
            
cache_get_field_content(i"friendName"gString); 
            new 
userID GetPlayerID(gString); 
            if(
userID != INVALID_PLAYER_IDonf ++; 
        } 
        
cache_delete(results);