title: How to check whether SELECT EXISTS returns a value or not?
body: <p>I am trying to quickly determine if a user_ID is the owner of a 'goal'. I believe my SQL query is good, but I'm trying to find a nice way of checking the result!</p>
  
  <p>In this case, no matter what I put for $obj_id or $user_id, my function returns true. I assume it's because mysql_num_rows is counting even a false result as a row? So what PHP code should I use to check to see if the result exists or not?</p>
  
  <p>Note that I want something short and elegant! I know I could do it the long way (check count(*), return mysql_assoc then check the count value...) but that is long winded and ugly.</p>
  
  <p>Any ideas? Thanks!</p>
  
  <pre><code>$query = "SELECT EXISTS (SELECT * FROM goals WHERE goal_ID='$obj_id' AND user_ID='$user_id')";
  if (@mysql_num_rows(mysql_query($query))!=1) {
      return false;
  } else {
      return true;
  }
  </code></pre>