title: PHP & MYSQL : building a query based on multiple input values from users
body: <p>Hypothetically I three tables:
  * recipes - contains recipes
  * ingredients - list of items
  * meals - list of meals</p>
  
  <p>I have a form that generates a selection like:</p>
  
  <pre><code>Choose what ingredients you have:
  - apples
  - bananas 
  - cherries
  
  Choose the meal this is for:
  - breakfast
  - lunch
  - dinner
  </code></pre>
  
  <p>I want the user to be able to choose from either or none of the above, i.e they may choose apples OR cherries OR (bananas &amp;&amp; lunch)</p>
  
  <p>When I query MySQL my query is roughly</p>
  
  <pre><code>select recipes.* from recipes
  </code></pre>
  
  <p>or</p>
  
  <pre><code>select recipes.* from recipes, ingredients 
  where recipes.id= ingredients.id and ingredients.list in ('apple');
  </code></pre>
  
  <p>or</p>
  
  <pre><code>select recipes.* 
  from recipes, ingredients, meal 
  where recipes.id= ingredients.id 
        and ingredients.list 
        and ingredients.id = meals.id 
        and ingredients.list ('apple') 
        and meals.list in ('lunch');
  </code></pre>
  
  <p>Is there a nice way of saying (in PHP) if this array exists (i.e. is_array(ingredients) add to the query the table (ingredients) and at the end tack on (".ingredients.list in ('apple'))...</p>
  
  <p>without having to write all the possible combinations or possible inputs (i.e. the user's selected from the ingredients list, or from the ingredients and meals list, or from no lists)?</p>