My join is not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: My join is not working (/showthread.php?tid=1211) |
My join is not working - andyblem - 02-19-2015 I have a search field in my form which searches data from a database and displays it on a result page. When I try to search data I get this error. Quote:A PHP Error was encountered I know the data I am passing to the view does not contain the 'names' field which means the query I am using is not retrieving this value from the database. Here is my database query Code: //this function gets all the contacts given a cerain parameter The 'names' field is in my office table, thus it must be my join function which is not working. Any help will be greatly appreciated RE: My join is not working - Avenirer - 02-19-2015 $this->db->join('offices', 'offices.id = phones.offices', 'left'); RE: My join is not working - marcos - 02-19-2015 Your query won't return the field 'names' because you aren't requesting it: "$this->db->select('users,numbers');". RE: My join is not working - edellascenza - 02-19-2015 At least tell us the structure of the tables you're trying to join, in any case a LEFT JOIN will bring you everything from the "left" table and NULL if no coincidence in "joined" table. RE: My join is not working - andyblem - 02-19-2015 I have three tables the phones table which has these fields(users, numbers, offices and id). The offices field is a foreign key which references the id field in the offices table. The offices table has these fields(names, id and departments). The departments field in the office table is a foreign key which references the id field in the departments table. The departments table has these fields(names, id). I want the query to return the results if the user enters a department or an office or a phone number RE: My join is not working - Rufnex - 02-20-2015 You haven't select your office.names, try this : PHP Code: $this->db->select('phones.users, phones.numbers'); |