do-while loop help(SQLite / Name checks)
#7

Quote:
Originally Posted by Stinged
Посмотреть сообщение
The problem is this:
The query is running only once.
It's formatted to %s = Name_1
It never re-formats to re-call the query to re-check if the name is available.

EDIT: You probably wont understand what I mean, so I'll explain it with comments.
pawn Код:
case DIALOG_FAIL_LOGIN:
{
    if( !response ) return SetTimerEx("KickTimer", 50, false, "i", playerid);
    if( response )
    {
        new Query[106], name[24], string[66], character = 1, DBResult:Result;
        format(name, sizeof(name), "%s_%d", GetName(playerid), character);
        format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s'", name);
        // Let's say the query is now this
        // SELECT * FROM `USERS` WHERE `NAME` = 'Example_1'
        Result = db_query(HDF, Query);
        if(db_num_rows(Result)) // If the name exists
        {
            do
            {
                character++;
                format(name, sizeof(name), "%s_%d", GetName(playerid), character);
                // You're adding the new number to the name.
                // But where are you adding it to the query?
                format(string, sizeof(string), "Skipping name '%s' because is in use.", name), SendClientMessage(playerid, COLOR_NOTES2, string);
            }
            while(db_next_row(Result)); // It's always checking for Example_1
        }
        else
        {
            format(string, sizeof(string), "Found a valid name - '%s' - setting. . .", name), SendClientMessage(playerid, COLOR_NOTES, string);
            SetPlayerName(playerid, name);

            SendClientMessage(playerid, COLOR_NOTES, "INFO: You will need to register now to save your stats");
            PlayerPlaySound(playerid,1057,0.0,0.0,0.0);

            ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{64CC66}Registration.", "{FFFFFF}Welcome to the server!\nYour name is detected as {64CC66}unregistered{FFFFFF}.\nYou are required to register to proceed playing.\n{64CC66}Enter your password below to complete the registration.", "Register", "Leave");
        }
        db_free_result(Result);
    }
}
Either I did something wrong.. but that made an infinite loop ;_;

@xXShadowXx: That worked, thanks
Reply


Messages In This Thread
do-while loop help(SQLite / Name checks) - by Kyance - 03.11.2014, 12:25
Re: do-while loop help(SQLite / Name checks) - by BroZeus - 03.11.2014, 14:16
Re: do-while loop help(SQLite / Name checks) - by Kyance - 03.11.2014, 14:40
Re: do-while loop help(SQLite / Name checks) - by Evocator - 03.11.2014, 15:15
Re: do-while loop help(SQLite / Name checks) - by Stinged - 03.11.2014, 15:34
Re: do-while loop help(SQLite / Name checks) - by xXShadowXx - 03.11.2014, 15:52
Re: do-while loop help(SQLite / Name checks) - by Kyance - 03.11.2014, 16:15

Forum Jump:


Users browsing this thread: 1 Guest(s)