mga_ka_php Posted May 20, 2010 Share Posted May 20, 2010 define('ORIGINAL_PRICE', 49.97); $computation = "ORIGINAL_PRICE - (ORIGINAL_PRICE * 0.50)"; echo (int) $computation; that code is not working but is that possible or how to code that to work? Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/ Share on other sites More sharing options...
-Karl- Posted May 20, 2010 Share Posted May 20, 2010 Perhaps something like this, if it's just simple maths you're trying to achieve? <?php $orig = 49.97; $computation = ($orig - ($orig * 0.50)); echo $computation; ?> Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060932 Share on other sites More sharing options...
mga_ka_php Posted May 20, 2010 Author Share Posted May 20, 2010 the reason why my i did that code because the computation will be coming from database and i don't know how to use the computation after i get it from the database. got the idea? Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060947 Share on other sites More sharing options...
mga_ka_php Posted May 20, 2010 Author Share Posted May 20, 2010 how do you compute an equation inside a variable? $row['equation'] - from database. example content: ORIGINAL_PRICE - (ORIGINAL_PRICE * 0.50) example define('ORIGINAL_PRICE', 49.97); $value = $row['equation']; is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060954 Share on other sites More sharing options...
dpacmittal Posted May 20, 2010 Share Posted May 20, 2010 Quote how do you compute an equation inside a variable? $row['equation'] - from database. example content: ORIGINAL_PRICE - (ORIGINAL_PRICE * 0.50) example define('ORIGINAL_PRICE', 49.97); $value = $row['equation']; is it possible? This is what you need: http://php.net/manual/en/function.eval.php Store the equation in database as: $ORIGINAL_PRICE - ($ORIGINAL_PRICE * 0.50) After that, you can do: $value = eval($row['equation']); Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060967 Share on other sites More sharing options...
mga_ka_php Posted May 20, 2010 Author Share Posted May 20, 2010 this is what i'm looking for! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060989 Share on other sites More sharing options...
dpacmittal Posted May 20, 2010 Share Posted May 20, 2010 You're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060992 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.