MySQL fetch
#1

my veriables in mysql are: Admin = 3 and On‌line = 1 but i get this:

http://www.part.lt/img/327efd92524a4...95d3a38586.png
thats not geting Online veriable or somethging IDK

pawn Код:
CMD:adminai(playerid, params[])
{
    new
        Index,
        query[ 300 ],
        str  [ 1200 ]
    ;

    mysql_query( "SELECT `Vardas`,`Admin`,`Online` FROM `vartotojai` WHERE `Admin` >  '0'" );
    mysql_store_result();
    if ( mysql_num_rows( ))
    {
        while( mysql_fetch_row( query ))
        {
            new
                name[ MAX_PLAYER_NAME ],
                adminid,
                OnlineEx;

            sscanf( query, "p<|>s[24]ii", name, adminid, OnlineEx );


            if ( !OnlineEx )
            {
                format( str, 1200, "{FFFFFF}%s%s - {FF0000}OFFLINE\n{FFFFFF}", str, name );
                Index++;
            }
            else
            {
                format( str, 1200, "{FFFFFF}%s%s - {00FF00}ONLINE\n{FFFFFF}", str, name );
                Index++;
            }
        }
    }
    mysql_free_result();
    if ( !Index )
    {
        ShowPlayerDialog( playerid, 7, DIALOG_STYLE_MSGBOX, "{FF0000}Administratoriai", "{FF0000}Atsiprasome siuo metu nera isrinktas nei vienas administratorius!", "Gerai", "" );
    }
    else
    {
        ShowPlayerDialog( playerid, 8, DIALOG_STYLE_MSGBOX, "{00FF00}Administratoriai", str, "Gerai", "" );
    }
    return 1;
}
pawn Код:
[22:28:29] CMySQLHandler::Query(SELECT `Vardas`,`Admin`,`Online` FROM `vartotojai` WHERE `Admin` >  '0') - Successfully executed.
[22:28:29] >> mysql_store_result( Connection handle: 1 )
[22:28:29] CMySQLHandler::StoreResult() - Result was stored.
[22:28:29] >> mysql_num_rows( Connection handle: 1 )
[22:28:29] CMySQLHandler::NumRows() - Returned 1 row(s)
[22:28:29] >> mysql_fetch_row_format( Connection handle: 1 )
[22:28:29] CMySQLHandler::FetchRow() - Return: Ance_Zas|1|1
[22:28:29] >> mysql_fetch_row_format( Connection handle: 1 )
[22:28:29] >> mysql_free_result( Connection handle: 1 )
[22:28:29] CMySQLHandler::FreeResult() - Result was successfully free'd.
[22:28:33] >> mysql_query( Connection handle: 1 )
Reply
#2

i think that mysql is fetching it wrong
Reply
#3

Hey, this command should tell players how many admins online are there right? Why dend a query for it?
Reply
#4

Quote:
Originally Posted by dusk
Посмотреть сообщение
Hey, this command should tell players how many admins online are there right? Why dend a query for it?
Yeah I wondered the same. There's no reason for you to update the database when an admin connects or leaves - that's just silly. Make a function instead!

pawn Код:
bool:IsAdminOnline(adminid)
{
    if( !IsPlayerAdmin( adminid )) // If the ID provided isn't an admin, this function should return false.
        return false;
    foreach( Player, i )
    {
        if( adminid == i ) // If the ID provided equals on of the online IDs (which foreach fetches for us) - then the player is online
            return true;
    }
    return false; // All other cases: Return false.
}
Without foreach:

pawn Код:
bool:IsAdminOnline(adminid)
{
    for( new i = 0, j = GetMaxPlayers(); i < j; i ++ )
    {
        if( adminid == i && IsPlayerAdmin( adminid ) && IsPlayerConnected( adminid )) // If the ID provided equals on of the online IDs (which foreach fetches for us) - then the player is online
            return true;
    }
    return false; // All other cases: Return false.
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)