【发布时间】:2016-01-28 23:59:03
【问题描述】:
我有 3 张表,分别是成分(ingredient_id,名称)、菜单(recipe_id、ingredient_id、category_id)和食谱(recipe_id、r_name、r_description)。
ingredient_id 名称
1 个洋葱
2 保罗
3 胡椒
4 油
recipe_id 成分_id category_id
1 3 1
1 4 1
2 3 1
2 4 1
recipe_id r_name r_description
1 Adobo 好吃
2 Kaldereta 恶心
我想要的是,如果我搜索 "Pepper, Oil" ,结果应该是与 adobo 和 kaldereta 成分相对应的食谱。
我试过了,但它只是静态的,我希望它是动态的,而且我想分解成分名称,以便我可以搜索多个单词。
public function get_halal()
{
$this->db->distinct();
$this->db->select('*');
$this->db->from('recipe');
$this->db->join('menu', 'menu.recipe_id = recipe.recipe_id');
$this->db->join('ingredient', 'ingredient.ingredient_id = menu.ingredient_id');
$this->db->where('menu.category_id = 1');
$this->db->like('ingredient.ingredient_name','Mango', 'both');
$query = $this->db->get();
return $query->result();
}
【问题讨论】:
-
你在使用Active Record吗?您是否有任何代码您尝试过但不太正确?
-
是的@Windle 我正在使用活动记录。我已经编辑了我的问题。请看一下。谢谢
标签: php mysql codeigniter