Formating 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Formating MySQL (
/showthread.php?tid=191227)
Formating MySQL -
Raimis_R - 18.11.2010
Hello I formating MySQL but i don't know What kind of string I need to set to format mysql.
Pvz.:
Код:
new query[200];
format(query,200,"UPDATE `"Test"` SET `Money` = '%i'"GetPlayerMoney(playerid));
return mysql_query(query);
This is just example
If new query[200]; is okey?
Re: Formating MySQL -
JaTochNietDan - 18.11.2010
That string is fine, however that query is not. That query will set the Money column of ALL rows in the table, you need to specify who you're setting it for, for example:
pawn Код:
new query[200];
format(query,200,"UPDATE `Test` SET Money = %i WHERE Username = '%s'",GetPlayerMoney(playerid),name[playerid]);
return mysql_query(query);
Obviously you'll need to sort out getting the name of the player yourself, what I gave is only an example if you were storing the name of players in an array.
Re: Formating MySQL -
Raimis_R - 18.11.2010
Okey but how my know if string is to big or to small?
Re: Formating MySQL -
JaTochNietDan - 18.11.2010
Well do some counting and some analyzing, lets see the string:
pawn Код:
UPDATE `Test` SET Money = %i WHERE Username = '%s'
The length of this string is 50 without any of the inserted values. So now lets check the values that will go into it:
Username: Max length of 24, so that makes the maximum length of the query, 74.
Money: How much money can a user have in your server? You've only used a maximum of 74 out of your specified 200, so unless a player can have over 125 digits in their money, then your string is definitely long enough, if not too long for this query, as I doubt a player should have over 125 digits in their money.
Edit: I made a slight error in calculation with the string length, without any inserted values from the format, it would be 46
Re: Formating MySQL -
Raimis_R - 18.11.2010
Okey thnx for helping