title: Decrement a database table value if value >= 1 else... Delete the record
body: <p>I want to decrement a database table value if the field value is greater than or equal to 1 (<code>&gt;= 1</code>). Otherwise (if it IS less than 1) then I want to delete that whole database record, My code decrements the value continuously but does not delete the record when it reaches less than 1.</p>
  
  <p>I think the <code>$Check</code> variable does not hold the <code>Quantity</code> field value but I'm not sure:</p>
  
  <p>Using MySQL</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$Check = "SELECT Quantity FROM Cart WHERE ItemCode = '1'";
  
  if($Check &gt;= '1')
  {
      $Query = "UPDATE Cart SET Quantity = Quantity - 1 WHERE ItemCode = '1'";
      mysql_query($Query);
  }
  else
  {
      $DeleteRow = "DELETE FROM Cart WHERE ItemCode = '1'";   
      mysql_query($DeleteRow);
  }
  
  mysql_close();
  </code></pre>