MySQL - Float doesnt Loads/Saves
#1

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(mysqlquerysizeof(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(playeridreason)
{
    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(playeridpos[0], pos[1], pos[2]); //let's get player's position when they leave your server
    
mysql_format(mysqlquerysizeof(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(mysqlquery"""");
    
//let's execute the query.
    
return 1;

Reply
#2

Check your mysql database - make sure that the field datatype is set to float, not int.
Reply
#3

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?
Reply
#4

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.
Reply
#5

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 ;(
Reply
#6

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 id='%d'",
Reply
#7

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 id='%d'",
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(mysqlquerysizeof(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]); 
Reply
#8

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'
Reply
#9

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?
Reply
#10

phpMyAdmin is part of XAMPP, that's what I've been using before too. XAMPP is the application that controls your localhost.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)