bine.heckmann Posted November 29, 2010 Share Posted November 29, 2010 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted November 29, 2010 Share Posted November 29, 2010 It doesn't work because of operator precedence. Add parentheses. . ($psc->value / 2) . You'll probably want a floor() or round() too. Quote Link to comment Share on other sites More sharing options...
bine.heckmann Posted November 29, 2010 Author Share Posted November 29, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.