php - 消息: Undefined index: when getting column name (two table with the same column) CodeIgniter

标签 php mysql codeigniter

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

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/

相关文章:

php - CodeIgniter fatal error

php - 测试不安全的结帐页面

mysql - Laravel Sum 列数据库 Eloquent

codeigniter - 如何使用 $this->config->item CODEIGNITER 仅调用数组中的一项?

php - 第三方资源在 CodeIgniter 中的位置在哪里?

php - 如何计算运行总计?

php - 使用PHP API在我的YouTube channel 中上传视频

PHP imagick COMPOSITE_DSTIN 结果有黑色背景

php - 如何使用正则表达式替换 PHP 中除第一个字符以外的所有字符?

MySql - 使用 1 列中的 2 个值计算时间距离(糟糕的设计解决方法)