Welcome Guest, Not a member yet? Register   Sign In
HOw do I write this join correctly using CI
#1

[eluser]justmelat[/eluser]
SELECT
contractors.lname,
contractors.fname,
jobs.`position`,
clients.companyName,
jobs.current
FROM
jobs
Inner Join contractors ON jobs.contractor_id = contractors.id
Inner Join clients ON jobs.company_id = clients.id
WHERE
jobs.current = 'Yes'
#2

[eluser]Seppo[/eluser]
If you want to use ActiveRecord

Code:
$this->db->select('contractors.lname, contractors.fname, jobs.position, clients.companyName, jobs.current');
$this->db->from('jobs');
$this->db->join('contractors', 'jobs.contractor_id = contractors.id', 'inner');
$this->db->join('clients', 'jobs.company_id = clients.id', 'inner');
$this->db->where('jobs.current', 'Yes');
$query = $this->db->get();
#3

[eluser]mironcho[/eluser]
Try something like this:
Code:
$this->db->select('contractors.lname, contractors.fname, jobs.`position`, clients.companyName, jobs.current');
$this->db->from('jobs');
$this->db->join('contractors', 'contractors.id = jobs.contractor_id', 'inner');
$this->db->join('clients', 'clients.id = jobs.company_id', 'inner');
$this->db->where(array('jobs.current' => 'Yes'));
$query = $this->db->get();
#4

[eluser]mironcho[/eluser]
One minute late... Smile
#5

[eluser]justmelat[/eluser]
I am not getting and error on this line of my view

<?php echo $this->table->generate($query); ?>

the error is:
A PHP Error was encountered
Severity: Notice

Message: Undefined variable: query

Filename: views/jobs_view.php

Line Number: 14
#6

[eluser]Seppo[/eluser]
Well... are you passing the $query var to the view?

Code:
$this->db->select('contractors.lname, contractors.fname, jobs.position, clients.companyName, jobs.current');
$this->db->from('jobs');
$this->db->join('contractors', 'jobs.contractor_id = contractors.id', 'inner');
$this->db->join('clients', 'jobs.company_id = clients.id', 'inner');
$this->db->where('jobs.current', 'Yes');
$data['query'] = $this->db->get();

$this->load->view('jobs_view', $data);
#7

[eluser]justmelat[/eluser]
Yes, I am.

Here is the controller:
function jobs()
{
$data['title']="PureStaff-Jobs";
$data['heading']="View Current Jobs";
//$data['query']=$this->db->get('jobs');

$this->db->select('contractors.lname, contractors.fname, jobs.`position`, clients.companyName, jobs.current');
$this->db->from('jobs');
$this->db->join('contractors', 'contractors.id = jobs.contractor_id', 'inner');
$this->db->join('clients', 'clients.id = jobs.company_id', 'inner');
$this->db->where(array('jobs.current' => 'Yes'));
$data['$query'] = $this->db->get();

$this->load->view('jobs_view.php', $data);
}

Here is the View:
</head>
<body>
<h2>&lt;?php echo $heading; ?&gt;</h2>
<p>&lt;?php echo anchor('purestaff/index','Back Home');?&gt;</p>
<hr>

&lt;?php $this->table->set_heading('JobID', 'ContractorID', 'CompanyID','Position','Start Date','End Date');?&gt;

&lt;?php echo $this->table->generate($query); ?&gt;
<hr>
&lt;/body&gt;
&lt;/html&gt;
#8

[eluser]Seppo[/eluser]
Code:
$data['$query']
should be
$data['query']
#9

[eluser]justmelat[/eluser]
WOW, i don't believe i did that. THANK YOU!!!!




Theme © iAndrew 2016 - Forum software by © MyBB