Example scenario; lets say I'm searching for employees and their employers
tblEmployee
eid | name
1 | james
2 | harry
tblCompany
cid | name
1 | ABC Ltd
2 | XYZ Corp
tblMappings
mid | eid | cid
1 | 1 | 2
James is assigned to the company XYZ Corp, but harry has no assignment. I want to pull out all employees whether they are assigned or not;
SELECT * FROM `tblEmployee`
LEFT JOIN `tblMappings` ON
`tblEmployee`.`eid` = `tblMappings`.`eid`
This returns the following in phpMyAdmin;
eid | name | mid | eid | cid
1 | james | 1 | 1 | 2
2 | harry | NULL | NULL | NULL
I'm performing the query in PHP and using:
while($row=mysql_fetch_assoc($results)) { ...blah.... }
But for harry $row['eid'] is blank. I'm not sure how to work this one out so any points would be greatly apprecited. Many thanks :)