title: MySQL Query not returning expected results
body: <p>Lets say I have the following information in a table.  -1 means Unlimited </p>
  
  <pre><code>Price    Minutes    SMS    Data
  7.50     200        -1     250
  10       250        -1     1000
  12       250        -1     -1
  </code></pre>
  
  <p>On my form I've got a number of fields and a checkbox if you want Unlimited of something so I have an SQL query which has a few variables depending on if the checkboxes are ticked like so:</p>
  
  <pre><code>//check to see if minutes is set as unlimited. if they are, set sms as -1
     if ($minunlim=="on"){
      $minquery = "minutes = -1";
      $minutes = "Unlimited";
     } else {
          $minutes = $_GET["minutes"];
      $minquery = "minutes &gt;= '$minutes' OR minutes = -1";
     }
  
  //check to see if sms is set as unlimited. if they are, set sms as -1
  if ($smsunlim=="on"){
      $smsquery = "sms = -1";
      $sms = "Unlimited";
  } else {
      $sms = $_GET["sms"];
      $smsquery = "sms &gt;= '$sms' OR sms = -1";
  }
  
  //check to see if sms is set as unlimited. if they are, set sms as -1
  if ($dataunlim=="on"){
      $dataquery = "data = -1";
      $data = "Unlimited";
  } else {
      $data = $_GET["data"];
      $dataquery = "data &gt;= '$data' OR data = -1";
  }
  
  //run query
  $getprices = $this-&gt;db-&gt;query("SELECT * FROM gg_Crates WHERE 
      price &lt;= '$price' AND $minquery
      AND ($smsquery)
      AND ($dataquery)");
  </code></pre>
  
  <p>So my criteria I used is Price = 36, Minutes = 100, SMS = 200, Data = 300 and my expectations are the in this instance, the only items returned would be row's where the price is 10 and 12 (because data is below 300 on the first row)</p>
  
  <p>The query it outputs is:</p>
  
  <pre><code>SELECT * FROM gg_Crates WHERE price &lt;= '36' AND minutes &gt;= '100' OR minutes = -1 AND (sms &gt;= '200' OR sms = -1) AND (data &gt;= '300' OR data = -1)
  </code></pre>
  
  <p>In my mind that reads</p>
  
  <blockquote>
    <p>Select everything where price is lower that 36, minutes are greater or
    equal to 100 or equal to -1.  And SMS are greater or equal to 200 or
    equal to -1. And data is greater or equal to 300 or equal -1</p>
  </blockquote>
  
  <p>There is no where in that statement where is should pull the 7.50 row as data is lower than 250.</p>
  
  <p>However the actual results I'm getting are that it's returning all 3 rows.  Any suggestions?</p>