Welcome Guest, Not a member yet? Register   Sign In
Select from multiple tables using active records
#1

[eluser]ethio[/eluser]
Hi,
I'm not just new to CodeIgniter, I'm new to PHP and MySql as well. Anyway, I'd like to select from multiple tables using a value posted(last_name) in the first table and using another value from this table(emp_no) and getting values in the second and third tables.

For example

Select 'emp_no', 'first_name', 'last_name',
From 'employees'
Select 'dept_no'
From 'dept_emp'
Select 'title'
From 'titles'
#2

[eluser]bigbusty[/eluser]
before you start programming serious apps, you should get familiar with sql and php basics. This way you wont achieve good results.
#3

[eluser]ethio[/eluser]
Ok I have looked at some SQL queries and this this exactly what I want. Could I at least get help converting this to activerecords?

SELECT e.emp_no, e.first_name, e.last_name, t.title, d.dept_no
FROM employees e JOIN titles t
ON (e.emp_no = t.emp_no)
JOIN dept_emp d
ON (e.emp_no = d.emp_no)
WHERE e.last_name = "something" ;

edited:
Is this right?
$this->db->select('e.emp_no, e.first_name, e.last_name, t.title, d.dept_no');
$this->db->from('employees AS e, titles AS t, dept_emp AS d');
$this->db->where('e.emp_no = t.emp_no');
$this->db->where('e.emp_no = d.emp_no');
$this->db->where('e.last_name', $name);
$data['query'] = $this->db->get();




Theme © iAndrew 2016 - Forum software by © MyBB