我想从两个具有相同列名的表中获取数据。我已经在列名中加了一些别名。但它不起作用。
调节器
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 } ?>
我希望你能帮助我们。并提前谢谢你。
试试这个,
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;
}