phpcodeigniteractiverecordresultsetgroup-concat

How to access a result set value which was generated by an SQL function call?


I want to groupconcat the product name, but it displaying undefined index product name in my view page when I try to access it.

Please help me to groupconcat product name.

Controller code:

$this->db->select('GROUP_CONCAT(prdtname)', false);
$this->db->from('purchaseitem');
$this->db->group_by('vno');
$query1=$this->db->get()->row_array();
$data['query1']= $query1;

I tried groupconcat in sql on my localhost it gives me an expected result, but I don't know where I had done mistake in converting to CodeIgniter.


Solution

  • Controller Code:

    $this->db->select('GROUP_CONCAT(prdtname)as itemname',false);
    $this->db->from('purchaseitem');
    $this->db->group_by('vno');
    

    View page:

    <td><?=$row['itemname'];?></td>