title: Testing a SQL Query for True or False
body: <pre><code>$sql = "SELECT # FROM users WHERE onduty = 1 AND loc_id = '{$site}';"; 
  $result = mysql_query($sql);
  </code></pre>
  
  <p>I simply want to test if this is true or false.  If it returns 0 rows, I want next line to be something like:</p>
  
  <pre><code>if (!$result) { //do this; }
  </code></pre>
  
  <p>However, in my test, I am getting false when I know it should be true.  Is this sound logic here?</p>
  
  <p><em><strong></em></strong>(note, yes I know I should be using <code>mysqli_query</code>, that is not what I am asking here)<strong>**</strong></p>
  
  <p><strong>ANSWER:
  This is what I used:</strong></p>
  
  <pre><code>$login_state = false;
  if(mysql_num_rows(mysql_query("SELECT 1 FROM users WHERE onduty = 1 AND loc_id = '{$site}';"))) {
      $login_state = true;
  }
  </code></pre>