title: MySQL and PHP - Calculating price of product in DB
body: <p>I am new to SQL and have been developing an inventory tracking system for a side business. I have developed it using PHP, MySQL and HTML. I have developed several features that will allow me to do some neat things. I have been stuck on figuring out how to calculate the price of a unit, made up of multiple components, once its assembled. </p>
  
  <p>Currently, I have 2 tables that I hoped would help me come up with the final price figure. </p>
  
  <h1>SQL Relationships</h1>
  
  <h2>Table 1: <code>Material_Inventory</code></h2>
  
  <pre><code>PRODUCT_ID (PK) | Quantity | Last Entry
  </code></pre>
  
  <p>This table helps me keep track of the quantity of each component in stock and keeps track of the last time a product was added</p>
  
  <h2>Table 2: <code>Orders</code></h2>
  
  <pre><code>Order_ID |  Product_ID | Item_quantity | Unit_price
  </code></pre>
  
  <p>This table helps me track the unit price of each individual component per order. I same "per order" because the price of a component could differ from order to order.  </p>
  
  <h1>Problem</h1>
  
  <p>In trying to calculate the price of a finalized built unit (component a + component b + component c). I am having a difficult time figuring out how to calculate the final price. This is the issue I am running into:</p>
  
  <ul>
  <li>How can I account for price change of the components?
          - For example, I am about to assemble 2 units. But component A in                                         the first unit has a different unit price than component A in the second unit.</li>
  </ul>
  
  <p>Any suggestion or any sort of feedback is greatly welcomed. </p>
  
  <p>Thank you so much for your time!</p>
  
  <p>cheers</p>