title: How to subtract db values using php
body: <p>How exactly do I subtract values from a database using php? I see plenty of examples using static variables such as </p>
  
  <pre><code>&lt;?php
  $first_number = 10;
  $second_number = 2;
  $third_number = 3;
  $sum_total = $third_number + $second_number * $first_number;
  print ($sum_total);
  ?&gt;
  </code></pre>
  
  <p>However I'm looking to subtract one database value from another, then multiply that value by another db value. To give some more detail, I have an inventory database where I'm echoing the values into a table, I'm attempting to subtract the total quantity of an item from the minimum quantity, to see how many need to be ordered, then multiply the number of parts we need to order by the cost of that part. I've dug around and found a few possible methods such as</p>
  
  <pre><code>$query = "SELECT `db`, 
           (`minimumquantity` - `totalquantity`) AS `quantitytoorder`
          FROM `db` 
          WHERE id ='".$id."';"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;?php
  $minimumquantity = $_GET['minimumquantity'];
  $totalquantity = $_GET['totalquantity'];
  
  $quantitytoorder = $minimumquantity - $totalquantity;
  print ($quantitytoorder);
  ?&gt;
  </code></pre>
  
  <p>Please before you laugh, I'm very much a beginner, can anyone point me in the right direction, or provide me with proper examples? My only real resource is the net and most examples I find are very high-level. </p>
  
  <pre><code>Field             Type        Null     Key   Default  Extra   
  id                int(3)      NO       PRI   NULL     auto_increment 
  partnumber        varchar(20) NO             NULL  
  description       varchar(20) NO             NULL  
  tonerprice        int(20)     NO             NULL  
  totalquantity     int(20)     NO             NULL  
  minimumquantity   int(20)     NO             NULL  
  quantitytoorder   int(20)     NO             NULL  
  replencost        int(20)     NO             NULL  
  </code></pre>