Jump to content

Math In Php Doesn't Do Math


Silvar

Recommended Posts

You have to use conditionals to determine what to do, you can't just concatenate things together and expect PHP to figure it out.

 

if ($gWithdrawDeposit == '+') $mathShit = $listAddupAmount + $gAmount
else if ($gWithdrawDeposit == '-') $mathShit = $listAddupAmount - $gAmount

 

This doesn't to what you think it does, as you've noticed already.

 

By using the concatenation operator (a period) between the variables you're treating them as strings, or said in other words: You're gluing text literals together. PHP has no concept of what these strings are, nor does it care. It just does what you tell it to. Same as writing "5500-1000" on a piece of paper, really.

As Kicken just posted, while I was writing this, you need to tell PHP what the content of the variables means. If you want something to happen on the basis of the input.

 

I would recommend that you read more up on strings in PHP, and basic PHP in general. Once you've wrapped your head around the basic syntax, operator types and value types, things should be a lot more logical for you. ;)

You have to use conditionals to determine what to do, you can't just concatenate things together and expect PHP to figure it out.

 

if ($gWithdrawDeposit == '+') $mathShit = $listAddupAmount + $gAmount
else if ($gWithdrawDeposit == '-') $mathShit = $listAddupAmount - $gAmount

I got another problem now. The ordering is wrong when i do "ORDER BY amount DESC". It's like the biggest number get moved a row down, because it's 1 digit longer than the others.

 

Illustration here:

OQIN6.jpg

 

How do I get the 4 digit numbers to be at their right position?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.