Jump to content

Divide a value from a query ?!


bine.heckmann

Recommended Posts

Hello everyone,

 

i'm trying to get the following scenario done:

 

I've got a shop system which is kind of a cms and shop in one thing but that's not really important here, now there's some kind of vouchers which can be used in my shop to fund the account balance aka "Credits", now everything works fine, my script checks the voucher for validity and balance and the user gets the voucher balance credited as his account balance, in short:

 

User1 uses Voucher with amount 10$

Script sets User1 Shop-Credits/Balance to 10$

 

Now what i want to achieve is, that the user get's only 50% of the original voucher amount credited to his shop-credits/balance basically just divide the voucher amount by 2 before it get's credited to the account.

 

My code to write/update the credits in mySQL looks like this:

 

$query2 = "UPDATE `shop_user` SET `credits` = `credits`+'".$psc->value."' WHERE `userid` = '".$_SESSION["userid"]."' AND `username` = '".$_SESSION["username"]."'";

 

Now this

.$psc->value.

is the part where it checks for the value first and then sets the same amount as "credits" in the shop.

 

Now isn't there just some simple piece of code that would let me divide this by 2, which would be 50% obviously.

 

something like

.$psc->value /2.

which obviously doesn't work, but should give you an idea of what i need.

 

Any help is greatly appreciated.

 

Sabine

 

Link to comment
https://forums.phpfreaks.com/topic/220111-divide-a-value-from-a-query/
Share on other sites

It doesn't work because of operator precedence. Add parentheses.

. ($psc->value / 2) .

You'll probably want a floor() or round() too.

 

Thank you for your reply, is the code you corrected / posted just meant to be an example, or would that actually work?

 

Sabine

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.