05.01.2017, 23:09
I've got this function:
Basically what it does is it gives a player a phone number, the first player to buy a phone gets the number 42455, and from there it should increase (42456, 42457, etc..). I got the first phone number working, but the second part of the code isn't working, in the database it just saves the row ID in the phone field instead of the increasing phone number. So what would be the correct query to use for this kind of thing?
P.S. if there is a simpler or more efficient way to do this please tell me, I suck with mysql stuff
Thanks in advance.
pawn Код:
stock GivePlayerPhone(playerid)
{
new Cache:result = mysql_query(g_SQL, "SELECT COUNT(*) FROM `players`");
new players;
cache_get_value_int(0, 0, players);
if(players == 1)
{
Player[playerid][Phone] = 42455;
cache_delete(result);
}
else
{
new Cache:lastPhone = mysql_query(g_SQL, "SELECT 'phone' FROM `players` ORDER BY MAX(id) DESC LIMIT 1)");
new phone;
cache_get_value_int(0, 0, phone);
Player[playerid][Phone] = phone + 1;
cache_delete(lastPhone);
}
}
P.S. if there is a simpler or more efficient way to do this please tell me, I suck with mysql stuff
Thanks in advance.