Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question mysql store calculation

    I'm trying to do what seems like a simple task on the surface.

    is it possible to store calculations in mysql and run them later on?

    for example if I had a field with " 1 + 1 "

    how could I execute that and have it return "2" ?

  • #2
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Why not just write an if statement, as well as a form so when a user enters 1 + 1 it echoes two?
    PHP Code:
    <?php echo "Microsuck says hi!"?>

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    let me explain a little more, though I'm thinking this is actually a php issue, not mysql.

    what I need to do is store mathematical equations like this:

    "GST * ( QST * AMT / 100 ) / 100"

    i then run a function on it to replace some of the string values with numbers. like this:

    "4.82 * ( 8.55 * 15 / 100 ) / 100"

    it prints out as a string, but how can I now execute this?

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Ok, i got it. this should have been in the php forum.

    answer is to use eval().

    PHP Code:
    eval("return $calc;"); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •