Association between 2 tables

2

I have a problem fetching data from 2 tables, both of which are associated. When I go into the browser and put the controller and then the method, it appears to me with this Array() message. Could someone tell me what the problem with my code is?

    public function categoria($slug_categoria = null){

    //Recebendo os dados das categorias
    $menu_categoria['categorias'] = $this->db->get('categorias')->result();

    //Criando querys SQL com JOIN usando o Active Record
    $this->db->select('r.id_receita, r.nome, r.slug_receita, r.foto, c.categoria');
    $this->db->from('receitas r');
    $this->db->join('categorias c', 'c.id_categoria = r.categoria', 'INNER');
    $this->db->where('c.slug_categoria', $slug_categoria);
    $this->db->order_by('r.nome', 'ASC');

    $receita['receitas'] = $this->db->get()->result();

    //Carregando as views 
    $this->load->view('html_header');
    $this->load->view('header');
    $this->load->view('menu_category', $menu_categoria);
    $this->load->view('categoria', $receita);
    $this->load->view('footer');
    $this->load->view('html_footer');       
}

I tried this:

<?php
echo heading("Receitas Deliciosas", 2);
if (count($receitas) > 0) {
    ?>
    <ul>
        <?php
        echo heading($receitas[0]->categoria, 3);
        foreach ($receitas as $item):
            ?>
            <li class="gradiente1 radious">
                <?php
                echo anchor("receita/" . $item->slug_receita, $item->nome);
                ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php
}else {
    echo "Nenhuma receita encontrada nesta categoria.";
}
?>

I made the loop and it executed echo "No recipe found ...".

    
asked by anonymous 14.06.2014 / 04:29

1 answer

1

This is because you are echoing a variable of type array. As it is not "printable", php plays the "type" on the screen.

In view, instead of

echo $receitas

Place

var_dump( $receitas );

And you will see your recipes. Obviously, this is just for debugging. To list the recipes, you will need to iterate in a loop, using foreach, for example.

    
14.06.2014 / 21:39