CodeIgniter Forums
Add fields to an active record query result - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Add fields to an active record query result (/showthread.php?tid=52345)



Add fields to an active record query result - El Forum - 06-07-2012

[eluser]anis2505[/eluser]
Hi,

I have to export some database data to excell sheet.
The data are stored on two DB tables tb1 and tb2. I want for to get only one single result for each element of tb1. joining the two table may result on more than one result for each tb1 elements

tb1(id_tb1, other fileds)
tb2(id_tb2, (FK) id_tb1, other fields)

I was thinking is it possible to add some other fields to an active record query result.
Please help I need it soo much

Code:
$query1 = $this->db->get('tb1');
foreach($query1->result() as $row1){
$id_tb1 = $row1->id_tb1;
$this->db->where('id_tb1',$id_tb1);
$query2 = $this->db->get('tb2');
foreach( $query2->result() as $row2{
  add_row2_fields_to_query1($query1,$row2);
}

}