CodeIgniter Forums

Full Version: sql query to CI query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Need help to need to translate this mysql query to CI query in comparing two tables

MYSQL query in which give me results in phpmyadmin
Code:
SELECT tb_payroll . *,tb_payroll2.*
FROM tb_payroll
LEFT JOIN tb_payroll2 ON tb_payroll.payroll_id = tb_payroll2.payroll_id
WHERE tb_payroll.net_pay != tb_payroll2.net_pay

here's my controller+model function
Code:
function discrepancy(){
  $this->db->select('tb_payroll.*, tb_payroll2.*');
  $this->db->from('tb_payroll');
  $this->db->join('tb_payroll2','tb_payroll.payroll_id = tb_payroll2.payroll_id','left');
  $this->db->where('tb_payroll.net_pay !=','tb_payroll2.net_pay');
  $data['query']=$this->db->get();
  $this->load->view("vdiscrepancy",$data,TRUE);
  $mpdf=new mPDF('c','A4','','',15,15,15,15,16,13);
  $mpdf->WriteHTML($html,2);
    $mpdf->Output();
}

my views in which I used different type of queries to have some result
Code:
<?php

foreach($query->result() as $row)
{
echo $row->tb_payroll.payroll_id;
echo $row->tb_payroll.net_pay;
echo $row->tb_payroll2.payroll_id;
echo $row->tb_payroll2.net_pay;
echo $row->net_pay;
echo $row->payroll_id;
}

?>
thanks

El Forum

[eluser]rana[/eluser]
So, you mean, your CI query not working, right? Are you getting some kind of error or so? If yes, please share the error, which will help us to get idea what is wrong more easily. Thanks.