我想从具有相同列名的两个表中获取数据。我已经在列名中添加了一些别名。但它不起作用。
Controller
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 仅接受两个参数,您传递了三个参数。
试试这个:
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;
}
关于php - 消息: Undefined index: when getting column name (two table with the same column) CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55931143/