Make a select in which to get the id of a select done previously

0

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

    
asked by anonymous 07.06.2016 / 17:58

2 answers

-1

The $list variable appears to be null. The reason for not bringing in the data from the database may be because the% cos_de% method of the ingredients model receives the getAllDisplayable_ing($id) parameter for the $id clause and when you call this method in the controller it does not pass that value by parameter. Checks if this value should be passed, if not, just remove the where clause that receives $this->db->where($id) . :)

    
09.06.2016 / 14:13
-1

I would do it that way, see if it helps:

function getAllDisplayable_ing($id=NULL)
 {

    $consuta = $this->db->get("lista_ingredientes")->result();
    foreach($consulta as &$valor){
        $this->db->where("id_menu",$valor->id_menu);
        $valor->submenu = $this->db->get("menus")->result();
    }
    return $consulta;
}

Passing data to view:

$data['dados_lista'] = $this->ingredientes_model->getAllDisplayable_ing();

When you fetch data from the view:

foreach($dados_lista as $valor){
    echo $valor->nome_ingrediente."<br>"; // ingrediente
    foreach($dados_lista->submenu as $valor_sub){
        echo $valor_sub->menu; // subitem
    }
}
    
09.06.2016 / 14:23