title: Writing a search filter -- filter at the SQL level or PHP level?
body: <p>I have an ajax filter on a search page that filters teacher results based on a set of criteria that can be manipulated by the user. I'm trying to decide whether to </p>
  
  <p>1) first go get all the teachers data, then in PHP make a new array of just those teachers who aren't affected by the negative filters</p>
  
  <p>or </p>
  
  <p>2) build an sql query with a number of WHERE clauses, i.e. 'WHERE pay = $pay &amp;&amp; city = $city &amp;&amp; distance &lt; $distance". </p>
  
  <p>Part of me thinks that number 2 might be a better option, but I'm already unsure of how to fill the query's variable values when the user hasn't specified a certain filter. So, for example, if $pay is undefined, the query will fail. in this case, what I would like to do is query teachers regardless of their pay.</p>