MySQL pays
#1

Hi! Every hour make pays, but get this error: [ERROR] cache_get_value_name: invalid row index 'X'

Код:
	    new STRING[ 128 ]; format( STRING, sizeof( STRING ), "SELECT * FROM users WHERE PayCheck != '0'" );
    mysql_tquery( MHandle, STRING, "MakePays", "d", 0 );
	 
	forward MakePays( playerid );
public MakePays( playerid )
{
    new rows, STRING[ 128 ], NAME[ 24 ], PAY;
    cache_get_row_count( rows ), printf( "%d", rows );
	    for( new i; i != rows; i ++ )
    {
        cache_get_value_name( i, "PlayerName", NAME );
        cache_get_value_name_int( i, "PayCheck", PAY );
	        mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE bank_accounts SET Balance=Balance+%d WHERE Owner='%s' && Disabled=0 LIMIT 1", PAY, NAME ), mysql_query( MHandle, STRING );
        mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE users SET PayCheck='0' WHERE PlayerName='%s' LIMIT 1", NAME ), mysql_query( MHandle, STRING );
	        for( playerid; playerid < MAX_PLAYERS; playerid ++ )
        {
            if( CompareEx( NAME, PlayerName( playerid ) ) )
            {
                if( IsPlayerConnected( playerid ) )
                {
                    SendFormatMessage( playerid, -1, "[{f3ff4a} SZERVER {ffffff}] Fizetйsed бtutalva a bankszбmlбdra! ( {f3ff4a}$%s{ffffff} )", FormatNumber( PAY ) );
                }
            }
        }
    }
    
    return 1;
}
But, this, works fine:

Код:
	    new STRING[ 128 ]; format( STRING, sizeof( STRING ), "SELECT PlayerName, Rank FROM users WHERE Fraction = '%d'", GetPlayerFraction( playerid ) );
		mysql_tquery( MHandle, STRING, "ShowMembers", "d", playerid );

public ShowMembers( playerid )
{
	if( GetPlayerFraction( playerid ) == 1 )
	{
	    new rows, PART[ 128 ], STRING[ 2024 ], NAME[ 24 ], RANG, RANK[ 24 ];

	    cache_get_row_count( rows );

	    for (new i; i != rows; i++)
	    {
	        cache_get_value_name( i, "PlayerName", NAME );
	        cache_get_value_name_int( i, "Rank", RANG );

			switch( RANG )
			{
			    case 1: RANK = "Sherrif";
			    case 2: RANK = "Undersherrif";
			    case 3: RANK = "Deputy-Sherrif";
			    case 4: RANK = "Academy-Student";
			}

	        format( PART, sizeof( PART ), "{ffffff}Nйv: {f3ff4a}%s{ffffff} Rang: {f3ff4a}%s\n", NAME, RANK ), strcat( STRING, PART );
	    }

	    ShowPlayerDialog( playerid, 1000, DIALOG_STYLE_MSGBOX, "{ffffff}Sherrif Tagok", STRING, "Rendben", "" );
	}

return 1;
}
Reply
#2

I don't think you can use != In SQL statements. Use

Код:
 SELECT * FROM Users WHERE Paycheck IS NOT '0'
Reply
#3

This not problem, works fine in another code ..
Reply
#4

Код:
SELECT * FROM users WHERE PayCheck > 0
Код:
public MakePays( playerid )
{
    new rows, STRING[ 128 ], NAME[ 24 ], PAY;
    cache_get_row_count( rows ), printf( "%d", rows );
if(rows > 0)
{
	    for( new i; i != rows; i ++ )
    {
        cache_get_value_name( i, "PlayerName", NAME );
        cache_get_value_name_int( i, "PayCheck", PAY );
	        mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE bank_accounts SET Balance=Balance+%d WHERE Owner='%s' && Disabled=0 LIMIT 1", PAY, NAME ), mysql_query( MHandle, STRING );
        mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE users SET PayCheck='0' WHERE PlayerName='%s' LIMIT 1", NAME ), mysql_query( MHandle, STRING );
	        for( playerid; playerid < MAX_PLAYERS; playerid ++ )
        {
            if( CompareEx( NAME, PlayerName( playerid ) ) )
            {
                if( IsPlayerConnected( playerid ) )
                {
                    SendFormatMessage( playerid, -1, "[{f3ff4a} SZERVER {ffffff}] Fizetйsed бtutalva a bankszбmlбdra! ( {f3ff4a}$%s{ffffff} )", FormatNumber( PAY ) );
                }
            }
        }
    }
    }
    return 1;
}
and change this
Код:
for( playerid; playerid < MAX_PLAYERS; playerid ++ )
{
    if( CompareEx( NAME, PlayerName( playerid ) ) )
    {
        if( IsPlayerConnected( playerid ) )
        {
            SendFormatMessage( playerid, -1, "[{f3ff4a} SZERVER {ffffff}] Fizetйsed бtutalva a bankszбmlбdra! ( {f3ff4a}$%s{ffffff} )", FormatNumber( PAY ) );
        }
    }
}
to this
Код:
for( playerid; playerid < MAX_PLAYERS; playerid ++ )
{
    if( IsPlayerConnected( playerid ) )
    {
        if( CompareEx( NAME, PlayerName( playerid ) ) )
        {
                SendFormatMessage( playerid, -1, "[{f3ff4a} SZERVER {ffffff}] Fizetйsed бtutalva a bankszбmlбdra! ( {f3ff4a}$%s{ffffff} )", FormatNumber( PAY ) );
        }
    }
}
Reply
#5

"Fraction" shouldn't be "Faction" ?
The error says the row is non-existant so one of your query is wrong.
Reply
#6

Now working, but, the most smaller run only .. so, if have 4 player who PayCheck > 0, code run 4x for the most smaller ID ..
Reply
#7

Quote:
Originally Posted by [HUN]Amf
Посмотреть сообщение
Now working, but, the most smaller run only .. so, if have 4 player who PayCheck > 0, code run 4x for the most smaller ID ..
Alright. Also, this code is pretty bad. I mean your loop is kind of false. IsPlayerConnected should be placed higher like that. Take a look at this one.
PHP код:
for(playerid 0MaxPlayer GetPlayerPoolSize(); playerid <= MaxPlayerplayerid++)
{
    if(!
IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
        continue;
    if( 
CompareExNAMEPlayerNameplayerid ) ) )
        
SendFormatMessageplayerid, -1"[{f3ff4a} SZERVER {ffffff}] Fizetйsed бtutalva a bankszбmlбdra! ( {f3ff4a}$%s{ffffff} )"FormatNumberPAY ) );

If still that doesn't work, can you please show the function "CompareEx".
Reply
#8

Don't see this part .. just the SQL part..

Код:
new STRING[ 128 ]; format( STRING, sizeof( STRING ), "SELECT PlayerName, PayCheck FROM users WHERE PayCheck > '1'" );
mysql_tquery( MHandle, STRING, "MakePays" );

public MakePays( )
{
    new rows, NAME[ 24 ], PAY, STRING[ 128 ];
    cache_get_row_count( rows ), printf( "%d", rows );

    for( new i; i != rows; i ++ )
   	{
       	cache_get_value_name( i, "PlayerName", NAME );
       	cache_get_value_name_int( i, "PayCheck", PAY ); printf( "%s - %d", NAME, PAY );

		mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE bank_accounts SET Balance=Balance+%d WHERE Owner='%s' && Disabled=0 LIMIT 1", pay, name ), mysql_query( MHandle, STRING );
	   	mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE users SET PayCheck='0' WHERE PlayerName='%s' LIMIT 1", name ), mysql_query( MHandle, STRING );
	}

    return 1;
}
Reply
#9

Quote:
Originally Posted by [HUN]Amf
Посмотреть сообщение
Don't see this part .. just the SQL part..

Код:
new STRING[ 128 ]; format( STRING, sizeof( STRING ), "SELECT PlayerName, PayCheck FROM users WHERE PayCheck > '1'" );
mysql_tquery( MHandle, STRING, "MakePays" );

public MakePays( )
{
    new rows, NAME[ 24 ], PAY, STRING[ 128 ];
    cache_get_row_count( rows ), printf( "%d", rows );

    for( new i; i != rows; i ++ )
   	{
       	cache_get_value_name( i, "PlayerName", NAME );
       	cache_get_value_name_int( i, "PayCheck", PAY ); printf( "%s - %d", NAME, PAY );

		mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE bank_accounts SET Balance=Balance+%d WHERE Owner='%s' && Disabled=0 LIMIT 1", pay, name ), mysql_query( MHandle, STRING );
	   	mysql_format( MHandle, STRING , sizeof( STRING ), "UPDATE users SET PayCheck='0' WHERE PlayerName='%s' LIMIT 1", name ), mysql_query( MHandle, STRING );
	}

    return 1;
}
This part seems to be fine. Check again what I wrote please.
Reply
#10

Why only most smaller player's id run only ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)