我有一個表格菜單,它由(recipe_id,ingredient_id,category_id),成分w/c組成(ingredient_id,name),category(category_id,name)和category_ingredient w/c由(ingredient_id,category_id)組成。我想獲得配方的所有成分,但我的代碼不起作用。請幫幫我。在codeigniter中獲取配方的成分
VIEW:
<form method="post">
<table class="table-responsive table table-hover">
<tr>
<td><strong>Recipe Ingredients</strong></td>
</tr>
<?php
foreach ($products as $product){
$product_id = $product['recipe_id'];
?>
<tr>
<td>
<?php foreach($this->products_model->getRecipeIngridients($product['recipe_id']) as $ing): ?>
<div class="col-sm-10"><li name="ingredients[]" value="<?php echo $ing->ingredient_id ?>" <?php echo (in_array($ing->ingredient_id)) ?>><?php echo $ing->name ?></li></div>
<?php endforeach; ?>
</td>
</tr>
<?php
}
?>
</table>
MODEL:
function getIngredientsInCategory($category_id)
{
$this->db->select('ingredient_id');
$this->db->where('category_id', $category_id);
$query = $this->db->get('category_ingredient');
foreach($query->result() as $row)
{
$ingredient[] = $row->ingredient_id;
}
$this->db->where_in('ingredient_id', $ingredient);
$query = $this->db->get('ingredient');
return $query->result();
}
function getRecipeIngridients($recipe_id)
{
$this->db->where('recipe_id', $recipe_id);
$query = $this->db->get('menu');
foreach($query->result() as $row)
{
$ingredient_id[] = $row->ingredient_id;
}
return $ingredient_id;
}
重複的問題??? – Kunal