12 Replies - 406 Views - Last Post: 01 June 2013 - 05:26 AM Rate Topic: -----

#1 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

storing earnings inside php my admin

Posted 19 May 2013 - 08:34 AM

Ok so i have a website were users can earn in game money but i need to store the in game money has 0.0000 but i have noticed my php script will add 0.0001 to it every time and when it hits 0.9999 it will not go over to 1.0000 i am using decimal(5,5) field for the column. I am guessing it would be better to use .int ?

This post has been edited by rpgmaker: 19 May 2013 - 09:16 AM

Is This A Good Question/Topic? 0
  • +

Replies To: storing earnings inside php my admin

#2 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 442
  • Joined: 28-July 09

Re: storing earnings inside php my admin

Posted 19 May 2013 - 10:04 AM

Hello there,

Would you be able to post the relevant PHP scripts that handle this bit so we can see what's going on and assist you better?
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3333
  • View blog
  • Posts: 11,296
  • Joined: 12-December 12

Re: storing earnings inside php my admin

Posted 19 May 2013 - 10:22 AM

Yes, my understanding is, if it is money - even game money! - it is better to store as integer, then only introduce decimals (pennies) when displaying the value.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,146
  • Joined: 08-June 10

Re: storing earnings inside php my admin

Posted 19 May 2013 - 12:04 PM

though DECIMAL should calculate correctly, as long as the calculation is done in SQL.

if you do the calculation in PHP, it will be converted to a FLOAT with all the problems of floating point arithmetics.
Was This Post Helpful? 1
  • +
  • -

#5 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

Re: storing earnings inside php my admin

Posted 19 May 2013 - 12:31 PM

well im doing a simple mysql update like so
  $fdfsdfdsfsdf = mysql_query("UPDATE users SET available_earning=available_earning+0.0001 WHERE id  = '".$owner2."'")
or die(mysql_error());


and when there money reaches 0.9999 it will not go over to 1.0000
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: storing earnings inside php my admin

Posted 20 May 2013 - 10:37 PM

View Postrpgmaker, on 19 May 2013 - 03:34 PM, said:

i am using decimal(5,5) field for the column. I am guessing it would be better to use .int ?

No, DECIMAL is generally the type you would want to use for currency that includes fractions. Using an integer is unnecessary, since DECIMAL, unlike FLOAT, stores the fractions in a completely reliable manner. No need to be dividing integers when that is the case.

The issue with your code is in the way you declare your field: DECIMAL(5,5). If you look through the docs for the type, you should spot the mistake there. - In short, the first number you declare represents the total number of digits the field will store, while the second number indicates how many of those numbers should be placed after the decimal point. So, in your declaration, you are telling MySQL to store 5 numbers per field, but are putting all of them after the decimal point. When your code reaches 1.0, MySQL has no place to put the 1.

If you were to look at the warnings generated after an attempt to update a field to 1 or higher, it would tell you the value is out of range.
Was This Post Helpful? 2
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6053
  • View blog
  • Posts: 23,488
  • Joined: 23-August 08

Re: storing earnings inside php my admin

Posted 21 May 2013 - 03:23 AM

I'm more than a little tired of people trying to program PHP with NO IDEA HOW SHIT WORKS!

Regarding your title, you're NOT storing ANYTHING in PHPMyAdmin! PHPMyAdmin is nothing more than a website on your machine that allows you to administer the MySQL database instances on that machine through a web UI, rather than using MySQL's command line interface or writing scripts. It doesn't store ANYTHING...MySQL stores data.

Sigh...I fear there's just way too much ignorance in the PHP community to overcome it. It's a losing battle.
Was This Post Helpful? 1
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,088
  • Joined: 08-August 08

Re: storing earnings inside php my admin

Posted 21 May 2013 - 06:45 AM

View PostJackOfAllTrades, on 21 May 2013 - 06:23 AM, said:

Sigh...I fear there's just way too much ignorance in the PHP community to overcome it. It's a losing battle.

There's plenty of ignorance in other languages too. PHP seems to have more willful ignorance though. My feeling is that lots of designers find they have a need to do some PHP coding but they also have no real interest in learning it. To them it's just another thing they need to bother with on their way to getting their design on their site(s).
Was This Post Helpful? 0
  • +
  • -

#9 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

Re: storing earnings inside php my admin

Posted 01 June 2013 - 01:51 AM

Ok so i am storing users earnings that they have made in side my database i have the column set has decimal(5,5) It seems has soon has the vale hits 0.99999 it will not go any higher example over to 1.00000 i am doing a simple update

  $fdfsdfdsfsdf = mysql_query("UPDATE users SET available_earning=available_earning+0.00002 WHERE id  = '".$owner2."'")
or die(mysql_error());


The update works in till the earnings get up to 0.99999 then stops. Any idea's what i can do ?

This post has been edited by rpgmaker: 01 June 2013 - 01:54 AM

Was This Post Helpful? 0
  • +
  • -

#10 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,205
  • Joined: 19-January 10

Re: storing earnings inside php my admin

Posted 01 June 2013 - 02:20 AM

What's $fdfsdfdsfsdf supposed to mean? That's not good naming conventions at all.

and we've been over this.
Was This Post Helpful? 0
  • +
  • -

#11 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: storing earnings inside php my admin

Posted 01 June 2013 - 02:33 AM

Duplicate threads merged.

I've already explained why this is happening. If my post isn't making sense to you, ask for clarification. Don't post the question again in a new thread.
Was This Post Helpful? 0
  • +
  • -

#12 rpgmaker  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 224
  • Joined: 02-October 11

Re: storing earnings inside php my admin

Posted 01 June 2013 - 02:40 AM

I have fixed this by using 8,5

This post has been edited by rpgmaker: 01 June 2013 - 02:44 AM

Was This Post Helpful? 0
  • +
  • -

#13 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,088
  • Joined: 08-August 08

Re: storing earnings inside php my admin

Posted 01 June 2013 - 05:26 AM

Great. Be sure to let us know when your site gets hacked!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1