Welcome Guest, Not a member yet? Register   Sign In
How do i use left join in code igniter
#1

[eluser]huangxiao[/eluser]
Hi, can i ask..i am still newbie on this code igniter and i am worry about how to use the left join,subquery etcc...can you please show me how to use in codeigniter.

this is my pdo sqlquery how do i convert this to codeigniter sqlquery...
for example like this....
Code:
$db->prepare("select emp.empno,emp.firstname,jb.empno,jb.jobname
                             from employee emp LEFT OUTER JOIN job jb
                             on emp.empno = job.empno");

  $cmd->execute();


please help me thannk you in advance.Smile


#2

[eluser]ivantcholakov[/eluser]
I work with CodeIgniter 3.0 dev, and the following code should work:

Code:
$query = $this->db
    ->select('emp.empno, emp.firstname, jb.jobname')
    ->from('employee AS emp')
    ->join('job AS jb', 'emp.empno = job.empno', 'left outer')
    ->get(); // See in the manual how to deal with query results.

As a result it builds the following raw query:

Code:
SELECT `emp`.`empno`, `emp`.`firstname`, `jb`.`jobname`
FROM `employee` AS `emp`
LEFT OUTER JOIN `job` AS `jb` ON `emp`.`empno` = `job`.`empno`

It is strange to me why the field jb.empno is placed, it is repetitive, I think. I removed it.

For lower version of CodeIgniter I did not test this. You may see this.
#3

[eluser]ivantcholakov[/eluser]
Not mandatory, but useful:

http://ellislab.com/codeigniter/user-gui...iling.html

For development purpose you may enable the profiler, it displays useful information at the bottom of the page. I shows the generated raw queries, so you can make comparison whether they are correct.

For production system disable the profiler.
#4

[eluser]huangxiao[/eluser]
Hi Thank you for the quick reply...and thank you for helping me.




Theme © iAndrew 2016 - Forum software by © MyBB