打趣我三代表的多個輸入值的查詢: *食譜 - 包含食譜 *成分 - 項目 列表*膳食 - 膳食PHP和MySQL:構建基於從用戶
的名單我有一個表格產生一個選擇,如:
Choose what ingredients you have:
- apples
- bananas
- cherries
Choose the meal this is for:
- breakfast
- lunch
- dinner
我希望用戶能夠從任何選擇或沒有以上的,即他們可以選擇蘋果或櫻桃OR(香蕉& &午餐)
當我查詢的MySQL我的查詢是大致
select recipes.* from recipes
或
select recipes.* from recipes, ingredients
where recipes.id= ingredients.id and ingredients.list in ('apple');
或
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');
有沒有說(在PHP)如果此數組存在的一個很好的方式(即is_array(成分)添加到查詢表(成分)和末尾粘性(「('蘋果'中的'.redredients.list))...
而不必編寫所有可能的組合或可能的輸入(即用戶選擇從成分表,或從成分和膳食清單,或者從沒有列出)?
對於一個格式良好的問題+1,特別是對於新用戶!你基本上想要'搜索標準' - 拉「涉及蘋果的所有食譜」和「所有涉及香蕉的午餐食譜」等? – 2010-09-04 10:32:26
你有沒有考慮過使用ORM?它將允許您以很少的努力構建動態查詢。 – DrColossos 2010-09-04 10:34:44
不是很好。實際上它很難讀取很長的一行 – 2010-09-04 10:40:28