MySQL SELECT problem.
#1

I made a stock which sets the player number to a random one, but first it would check if someone else has in inside the database,

pawn Код:
stock SetPlayerNumber(playerid)
{
    new number = randomEx(123456, 999999);
    new query[256];
    format(query, sizeof(query), "SELECT `number` FROM `users` WHERE `number` = %d", number);
    mysql_function_query(dbHandle, query, true, "CheckNumber", "ii", playerid, number);
}

CheckNumber:
public CheckNumber(playerid, number)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
        SetPlayerNumber(playerid); //Have to set player number again, if it has been found already.
    }
    else
    {
        PlayerInfo[playerid][pNumber] = number;
    }
    return 1;
}
It sets my number, but when I print it, it shows the old number not the new one.

Here is an example:
pawn Код:
case 0:
            {
                if(GetCash(playerid) < CELLPRICE) return NoCashMSG(playerid);
                BizInfo[BizEntered[playerid]][bizCash] += CELLPRICE;
                PlayerInfo[playerid][pCellPhone] = 1;
                SetPlayerNumber(playerid);
                GiveCash(playerid, -CELLPRICE);
                SCM(playerid, COLOR_GRAD4, "Cellphone Purchased.");
                format(string, sizeof(string), "Your new phone number is: %d", PlayerInfo[playerid][pNumber]);
                SCM(playerid, COLOR_INFO, string);
                SCM(playerid, COLOR_WHITE, "HINT: /cellhelp");
            }
Reply
#2

You have to code in the callback
pawn Код:
{
    if(GetCash(playerid) < CELLPRICE) return NoCashMSG(playerid);
    BizInfo[BizEntered[playerid]][bizCash] += CELLPRICE;
    PlayerInfo[playerid][pCellPhone] = 1;
    SetPlayerNumber(playerid);
}
pawn Код:
stock SetPlayerNumber(playerid)
{
    new number = randomEx(123456, 999999);
    new query[256];
    format(query, sizeof(query), "SELECT `number` FROM `users` WHERE `number` = %d", number);
    mysql_function_query(dbHandle, query, true, "CheckNumber", "ii", playerid, number);
}
pawn Код:
public CheckNumber(playerid, number)
{
    new rows, fields, string[128];
    cache_get_data(rows, fields);
    if(rows)
    {
        SetPlayerNumber(playerid); //Have to set player number again, if it has been found already.
    }
    else
    {
        PlayerInfo[playerid][pNumber] = number;
        GiveCash(playerid, -CELLPRICE);
        SCM(playerid, COLOR_GRAD4, "Cellphone Purchased.");
        format(string, sizeof(string), "Your new phone number is: %d", PlayerInfo[playerid][pNumber]);
        SCM(playerid, COLOR_INFO, string);
        SCM(playerid, COLOR_WHITE, "HINT: /cellhelp");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)