MySQL - Float doesnt Loads/Saves -
Saize - 21.01.2015
Hey guys, Iґve got another small problem with MySQL
I tried to set the Players Position by Floats thatґll get set into the SQL-DB.
But it still just shows it as an Integer
And It doesnt save the Floats, it just stays at the same Integer
Codes:
Register:
PHP код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `PosX`, `PosY`, `PosZ`, `FacingAngel`) VALUES ('%e', '%s', 701.8041,-519.4351,16.3318,261.1537)", Name[playerid], pInfo[playerid][Password]);
Saving:
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
new query[128], Float:pos[3]; //query[128] is for formatting our query and Float:pos[3] is for getting and saving player's position
GetPlayerPos(playerid, pos[0], pos[1], pos[2]); //let's get player's position when they leave your server
mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Score`=%d, `VIP`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f WHERE `ID`=%d",\
pInfo[playerid][Score], pInfo[playerid][VIP], pInfo[playerid][Money], pos[0], pos[1], pos[2], pInfo[playerid][AccID]);
//We update the table(`players`) by getting player's admin level, vip level, money, and positions and save them in the database
mysql_tquery(mysql, query, "", "");
//let's execute the query.
return 1;
}
Re: MySQL - Float doesnt Loads/Saves -
EnforcerDon - 21.01.2015
Check your mysql database - make sure that the field datatype is set to float, not int.
AW: Re: MySQL - Float doesnt Loads/Saves -
Saize - 21.01.2015
Quote:
Originally Posted by EnforcerDon
Check your mysql database - make sure that the field datatype is set to float, not int.
|
Yep it is set to float, I just made it like in this
Tutorial and addet some variabled by myself to learn how to work with MySQL
Someones got an Idea what I did wrong?
Re: MySQL - Float doesnt Loads/Saves -
Misiur - 21.01.2015
As a sidenote: Your query string array is to small. With placeholders it's 108 characters long, and if you don't specify float precision, each will take at least 8 characters (0.000000). Use precision specifier like %.2f, or make the array bigger than 128.
AW: Re: MySQL - Float doesnt Loads/Saves -
Saize - 21.01.2015
Quote:
Originally Posted by Misiur
As a sidenote: Your query string array is to small. With placeholders it's 108 characters long, and if you don't specify float precision, each will take at least 8 characters (0.000000). Use precision specifier like %.2f, or make the array bigger than 128.
|
Well I changed the length in the DB from 10 to 20 and edited the querystring ^^
+ I added %.6f but its still saving the coordinations as an integer ;(
Re: MySQL - Float doesnt Loads/Saves -
Eyce - 21.01.2015
I use "double" for my table when saving floats, so it's like:
Код:
`PosX` double NOT NULL DEFAULT '0.0'
Edit: You can also remove "\" after
AW: Re: MySQL - Float doesnt Loads/Saves -
Saize - 21.01.2015
Quote:
Originally Posted by Eyce
I use "double" for my table when saving floats, so it's like:
Код:
`PosX` double NOT NULL DEFAULT '0.0'
Edit: You can also remove "\" after
|
Where do Iґve gotta add "`PosX` double NOT NULL DEFAULT '0.0'"?
Back in the days I used Dini and now Iґm testing a bit around with MySQL so dont get mad because of this kinda... weird question please
The "\" is set because I use two Lines in this code ^^
PHP код:
mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Score`=%d, `VIP`=%d, `Money`=%d, `posX`=%.6f, `posY`=%.6f, `posZ`=%.6f WHERE `ID`=%d",\
pInfo[playerid][Score], pInfo[playerid][VIP], pInfo[playerid][Money], pos[0], pos[1], pos[2], pInfo[playerid][AccID]);
Re: MySQL - Float doesnt Loads/Saves -
Eyce - 21.01.2015
Oh that's just an example when creating your table, it simply means change float to double in your phpMyAdmin or SQL file.
As for the "\" - this is used for strings inside " " - from what I know, such as:
pawn Код:
mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Score`='%d', \
VIP='%d' WHERE id='%d'", pInfo[playerid][Score], pInfo[playerid][VIP], pInfo[playerid][AccID]);
And one more thing, when you update your tables, always use ' ' for them. Like:
pawn Код:
`Score` = '%d', `PosX` = '%f'
AW: Re: MySQL - Float doesnt Loads/Saves -
Saize - 21.01.2015
Quote:
Originally Posted by Eyce
Oh that's just an example when creating your table, it simply means change float to double in your phpMyAdmin or SQL file.
As for the "\" - this is used for strings inside " " - from what I know, such as:
pawn Код:
mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Score`='%d', \ VIP='%d' WHERE id='%d'", pInfo[playerid][Score], pInfo[playerid][VIP], pInfo[playerid][AccID]);
And one more thing, when you update your tables, always use ' ' for them. Like:
pawn Код:
`Score` = '%d', `PosX` = '%f'
|
Well Iґm not using phpMyAdmin, the only Programms I use are Xampp and Navicat Lite, can I add it with navicat lite too?
Re: MySQL - Float doesnt Loads/Saves -
Eyce - 21.01.2015
phpMyAdmin is part of XAMPP, that's what I've been using before too. XAMPP is the application that controls your localhost.