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

vd2z7a6w  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(81)

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

控制器

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 } ?>
xxslljrj

xxslljrj1#

CI选择只接受两个参数,而您传递了三个。
试试这个:

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;
}

相关问题