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? 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; ?> 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? 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? 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 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']); 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! 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. Link to comment https://forums.phpfreaks.com/topic/202339-is-this-possible/#findComment-1060992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.