PHP & MYSQL : building a query based on multiple input values from users

Hypothetically I three tables:* recipes - contains recipes* ingredients - list of items* meals - list of mealsI have a form that generates a selection like:\[code\]Choose what ingredients you have:- apples- bananas - cherriesChoose the meal this is for:- breakfast- lunch- dinner\[/code\]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 && lunch)When I query MySQL my query is roughly\[code\]select recipes.* from recipes\[/code\]or\[code\]select recipes.* from recipes, ingredients where recipes.id= ingredients.id and ingredients.list in ('apple');\[/code\]or\[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\]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'))...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)?
 
Back
Top