Inserting random values in MYSQL.
#1

Hello, I have a quick question.
I have a SQL saving system and I have a shop system in which you can buy a cellphone and such.

pawn Код:
PlayerInfo[playerid][pNumber] = randomEx(1234567, 9999999);
format(query, sizeof(query), "UPDATE `users` SET `cellphone` = '1'", GetStringVar(playerid, "Cellphone"), GetName(playerid));
mysql_function_query(dbHandle, query, false, "", "");
Is there a way in MYSQL to add a random value like shown in the code randomEx(1234567, 9999999); as it's needed for my saving system. Thanks in advance.
Reply
#2

you want to save random number into "cellphone" column ?
what is the name of column that you store "Player nick" into it ?
Reply
#3

No, I want to save a random number in the 'number' column.
Reply
#4

so what is your player nick column ?

i don't want to dubble posting so i edited you script just change column names with your own column name

ColumnX ~~~> Player nick column name

pawn Код:
PlayerInfo[playerid][pNumber] = randomEx(1234567, 9999999);
format(query, sizeof(query), "UPDATE `users` SET `number` = %d WHERE `ColumnX` = %s", PlayerInfo[playerid][pNumber], GetName(playerid));
mysql_function_query(dbHandle, query, false, "", "");
Reply
#5

Thanks for the help I found it out myself, I'll explain..
I have a table called users and the column called number, the column number I wanted to edit.
I made the code like this..
pawn Код:
format(query, sizeof(query), "UPDATE `users` SET `number` = %d", PlayerInfo[playerid][pNumber], GetName(playerid));
                mysql_function_query(dbHandle, query, false, "", "");
And it works.


EDIT: I got one more question, is there a way to add a number to an existing number..
For example I got 2 cigars and I buy one more from the store and it gives me 3 in total..
I have this code.
pawn Код:
PlayerInfo[playerid][pCigars] += 1;
How could I make that into MYSQL, the column name is cigars.
Reply
#6

Your code is wrong !
You update users table and number column but you have to define WHiCH row you want to update ? All users have number column ! You ha e to put WHERE playername = something (loock at my post above and read query)
Don't send query to database when player buy cigaret
Just store it into a variable and save it on player disconnect !
Reply
#7

You can do math in MySQL and I honestly prefer saving data intermittently, rather than sending one huge query on disconnect. If the server unexpectedly crashes then all the currently connected players will lose all their stats for that session, whereas with intermittent saves they will only lose a few stats or none at all.

PHP код:
UPDATE character SET cigars cigars 1 WHERE charid = ... 
Reply
#8

Thanks guys, I managed to fix it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)