SA-MP Forums Archive
help with mysql - 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: help with mysql (/showthread.php?tid=490566)



help with mysql - ancezas - 27.01.2014

hi i have this code:
Quote:

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

mysql_query( "SELECT `vardas`,`admin`,`online` FROM `zaidejai` 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 - %s - {FF0000}OFFLINE\n{FFFFFF}", str, name, ReplaceAdminName( adminid ) );
Index++;
}
else
{
format( str, 1200, "{FFFFFF}%s%s - %s - {00FF00}ONLINE\n{FFFFFF}", str, name, ReplaceAdminName( adminid ) );
Index++;
}
}
}
mysql_free_result();
if ( !Index )
{
ShowPlayerDialog( playerid, 2501, DIALOG_STYLE_MSGBOX, "{FF0000}Adminai", "{FF0000}Atsiprasome siuo metu nera isrinktas nei vienas direktorius!", "Gerai", "" );
}
else
{
ShowPlayerDialog( playerid, 2502, DIALOG_STYLE_MSGBOX, "{00FF00}Adminai", str, "Gerai", "" );
}
return 1;
}

but even admin is online it says offline and doesnt show ReplaceAdminName


Re: help with mysql - Mystique - 27.01.2014

Wait a second.... Are you telling me that this script should show a list of online admins? If so, you don't even need mysql.


Re: help with mysql - Scottas - 27.01.2014

Do you set `online` value when admin connects to server? You should check if variables have correct values:
pawn Код:
print(query);
printf("%s %d %d", name, adminid, OnlineEx);



Re: help with mysql - ancezas - 27.01.2014

Quote:
Originally Posted by Mystique
Посмотреть сообщение
Wait a second.... Are you telling me that this script should show a list of online admins? If so, you don't even need mysql.
i want that it show online and offline


Re: help with mysql - ancezas - 27.01.2014

Quote:

print(query);
printf("%s Admin id: %d Online: %d", name, adminid, OnlineEx);

shows zeros


Re: help with mysql - Scottas - 27.01.2014

Can you compare printed results with results in mysql database? Take a look what mysql_log contains, maybe you will see some errors. Also I would recommend to use latest version of this plugin.


Re: help with mysql - ancezas - 27.01.2014

in sql debug it show me this:
Quote:

[10:44:34] CMySQLHandler::FetchRow() - Return: Ance_Zas|3|1

it's from this code:
Quote:

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

why it show me |?


Re: help with mysql - Scottas - 27.01.2014

Its OK. Try this and tell me, what your server log shows.
pawn Код:
CMD:adminai(playerid,params[])
{
    new
        Index,
        query[ 300 ],
        str  [ 1200 ];

    mysql_query( "SELECT `vardas`,`admin`,`online` FROM `zaidejai` 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 );
            //  Print result
            print(query);
            printf("%s, %d, %d", name, adminid, OnlineEx);

            if ( !OnlineEx )
            {
                format( str, 1200, "{FFFFFF}%s%s - %s - {FF0000}OFFLINE\n{FFFFFF}", str, name, ReplaceAdminName( adminid ) );
                Index++;
            }
            else
            {
                format( str, 1200, "{FFFFFF}%s%s - %s - {00FF00}ONLINE\n{FFFFFF}", str, name, ReplaceAdminName( adminid ) );
                Index++;
            }
        }
    }
    mysql_free_result();
    if ( !Index )
    {
        ShowPlayerDialog( playerid, 2501, DIALOG_STYLE_MSGBOX, "{FF0000}Adminai", "{FF0000}Atsiprasome siuo metu nera isrinktas nei vienas direktorius!", "Gerai", "" );
    }
    else
    {
        ShowPlayerDialog( playerid, 2502, DIALOG_STYLE_MSGBOX, "{00FF00}Adminai", str, "Gerai", "" );
    }
    return 1;
}



Re: help with mysql - ancezas - 27.01.2014

it gives me:
Quote:

[11:57:06] Ance_Zas|3|1
[11:57:06] Ance_Zas|3|1, 0, 0




Re: help with mysql - Scottas - 27.01.2014

any sscanf warnings? You are using sscanf plugin or just pawn function?