Top queries (SQL)
#1

Hi,

I'm not sure why string2 isn't printing in the client message as it should be the value of 'kills'.

It's pretty messy code at the moment so don't criticize me on that, I'm just trying to get the first part to work, tia


Code:
COMMAND:top(playerid,params[])
{
    new
    	string[64], string2[64], query[128],
    	DBResult:result;
    	DBResult:result2;

    format(query,sizeof(query),"SELECT `Name` FROM `USERS` ORDER BY (`KILLS` * 1) DESC limit 3");
    result = db_query(Database,query);

    for(new a;a<db_num_rows(result);a++)
    {
        db_get_field(result,0,string,128);
        format(query,sizeof(query),"SELECT `KILLS` FROM `USERS` WHERE `Name` = lower('%s')",string);
        result2 = db_query(Database,query);
        db_get_field(result2,0,string2,128);

        format(string,sizeof(string),"%d. %s Amount (%d)",a+1,string, string2); 
        SendClientMessage(playerid,-1,string);

        db_next_row(result);
        db_free_result(result2);
    }
    db_free_result(result);
    return 1;
}
Looks like this, but the Kill value isn't printing
"1. Hitler Amount (16)"
"2. Frank Amount (12)"
"3. outlawz Amount (5)"
Reply
#2

because its string not integer? %d to %s
Reply
#3

That should work:
pawn Code:
COMMAND:top( playerid, params[ ] )
{
    new
        string[ 44 ],
        info[ 2 ][ MAX_PLAYER_NAME ],
        DBResult: result
    ;

    result = db_query( Database, "SELECT Name, KILLS FROM USERS ORDER BY KILLS DESC LIMIT 3" );

    for( new a; a != db_num_rows( result ); a++ )
    {
        db_get_field( result, 0, info[ 0 ], MAX_PLAYER_NAME );
        db_get_field( result, 1, info[ 1 ], 7 );

        format( string, sizeof( string ), "%d. %s Amount (%d)", a + 1, info[ 0 ], strval( info[ 1 ] ) );
        SendClientMessage( playerid, -1, string );

        db_next_row( result );
    }
    db_free_result( result );
    return 1;
}
Reply
#4

Great, but for some reason it's still not getting accurate results. Let me do some testing,

Edit, missed out something;
Code:
result = db_query( Database, "SELECT Name, KILLS FROM USERS ORDER BY KILLS * 1 DESC LIMIT 3" );
Thanks for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)