I'm on a page where you're printing data from a menu. And underneath these data I want you to show me the ingredients of this menu, and I'm going to look for them in an array_list.
Controller:
function lista_ingre()
{
$this->load->model('ingredientes_model');
$data['list'] = $this->ingredientes_model->getAllDisplayable_ing();
//var_dump($data['list']); exit;
$data['username'] = $this->session->userdata('username');
$this->load->view('menus_detalhes_user',$data);
}
Menu Model:
function GetDisplayableByUsername_u($id)
{
//indica os campos
$this->db->select('id_menu, foto, nome, descricao, preco ');
$result = $this->db->get_where('menus',array('id_menu' => $id));
return $result->row();
}
Ingredients Model:
function getAllDisplayable_ing($id)
{
$this->db->select('id_ingrediente, lista_ingredientes.id_menu, nome_ingrediente, quantidade');
$this->db->from('lista_ingredientes');
$this->db->join('menus', 'menu.id_menu = lista_ingredientes.id_menu');
$this->db->where('menu.id_menu', $id);
$result = $this->db->get();
return $result->result();
}
Menu View:
<p class="text-muted"><?php echo $menus->nome?></p>
<p class="text-muted"><?php echo $menus->preco?>€</p>
View the ingredients:
<?php foreach ($list as $lista_igredientes): ?>
<div class="service-box">
<img src="" class="img-responsive" alt="">
<h3><?php echo $lista_igredientes->nome_ingrediente?></h3>
<p class="text-muted"><?php echo $lista_igredientes->quantidade?></p>
</div>
<?php endforeach ?>
The menu data appears well in the view, but the ingredient data does not. The error is: Undefined variable: list and Invalid argument supplied for foreach ()
Thank you