【问题标题】:How to get data menu and sub-menu in two table with codeigniter如何使用codeigniter在两个表中获取数据菜单和子菜单
【发布时间】:2018-03-26 04:01:23
【问题描述】:

我有问题。如何连接2个表并根据对应的菜单ID显示子菜单

我的数据库: enter image description here

我的模型是

function get_all_bantuan(){
    $this->db->select('*');
    $this->db->from('kategori');
    $r = $this->db->get();
    return $r->result();
}

function get_isi_kategori_bantuan(){
    $this->db->select('*');
    $this->db->from('kategori a');
    $this->db->join('menu_kategori b', 'a.id_kategori=b.id_kat');
    $this->db->where('b.status','on');
    $r = $this->db->get();
    return $r->result_array();
}

我的控制器:

$data['info'] = $this->Halaman_bantuan_m->get_all_bantuan();
$data['sub_info'] = $this->Halaman_bantuan_m->get_isi_kategori_bantuan();

$this->load->view('headerHelp',$data);

我的看法是:

<div class="row">
    <?php 
        foreach($info as $row){ 
    ?>
        <div class="col-md-3 col-xs-12 dsg">
            <div class="hlp co_num1">
                <h3 class="djnl"><?php echo $row->kategori?></h3>
                <ul class="list-unstyled">
                <?php 
                    foreach($sub_info as $row){ 
                ?>
                    <li class="ct-sub"><a href="<?php echo base_url('bantuan/');?><?php echo $row['slug'];?>"><?php echo $row['menu'];?> <i class="glyphicon glyphicon-play plb pull-right"></i></a></li>
                <?php }?>
                </ul>
            </div>
        </div>
    <?php }?>
</div>

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    不需要 where 条件,因为在您的数据库表中没有称为状态的字段。

    return $this->db->join('menu_kategori', 'id_kategori=id_kat','left')->get('kategori')->result_array();
    

    【讨论】:

      猜你喜欢
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多