The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End how do you do math in php?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #30170

    I want to know how you do math in php? for example. Lets say I have a database that is to hold information about personal loans. So I store a number in the database. I know that I can retrieve the information with a query. So is it just that you use the query and assign it to a variable? Like

    $amount = “SELECT amount FROM tblAMOUNT”;

    The idea that I am trying to figure out is if you have a form to enter an amount for a payment. How to deduct the amount entered from the last amount entered? Make sense?


    Take a read here, I personally find this a very helpful site.

    Anyway, math in PHP can be done with so-called operators.
    Say you have 2 amounts entered, one called $amountOne and the other $amountTwo.
    To subtract the first from the latter one, you could do this:

    $amountOne = 5;
    $amountTwo = 10;
    $newAmount = $amountTwo - $amountOne;

    echo "$newAmount"


    Er… You’re mixing up database queries and arithmetic here. I think you need to sit down for a few days with a good PHP/MySQL primer!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.