消息:未定义的索引:获取列名时(两个具有相同列的表)Codeigniter

问题描述 投票:0回答:1

我想从两个具有相同列名的表中获取数据。我已经在列名中加了一些别名。但它不起作用。

调节器

public function price_master_list(){

    $result['mediacat'] = $this->em->getmedia_with_category();
    $this->load->view('price_master_list',$result);
}

模型

function getmedia_with_category(){
    $query2 = $this->db->select('*','m.name as `catname`', false)->from('media as m')->join('media_category as c', 'c.media_id = m.id')->where('m.delete_flag','1')->get();
    $response = $query2->result_array();
    return $response;
}

视图

<?php foreach($mediacat as $medcat){ ?>
<tr>
    <td><?php echo $medcat['catname']; ?></td>
</tr>
<?php } ?>

我希望你能帮助我们。并提前谢谢你。

php mysql codeigniter
1个回答
0
投票

试试这个,

CI select只接受两个params,你通过了三个

function getmedia_with_category(){
    $query2 = $this->db->select('m.*,c.name as catname', false)->from('media as m')->join('media_category as c', 'c.media_id = m.id')->where('m.delete_flag','1')->get();
    $response = $query2->result_array();
    return $response;
}
© www.soinside.com 2019 - 2024. All rights reserved.