I'm trying to learn how to extract data from multiple tables and put them into a variable and return them to my controller.
I can get information from one single table like this:
$this->db->select('first_name, last_name');
$this->db->from('people');
$this->db->where('first_name', $firstname);
$this->db->where('last_name', $lastname);
$result = $this->db->get();
but I'm confused as to how I can get data from another table and match them with other variables holding more of the users input.
I've read the Active Record documentation on the CI website but the only thing I found that could be what I'm looking for is the join() query, but I don't how to use it, the example doesn't help on the website because I don't understand this:
$this->db->join('comments', 'comments.id = blogs.id');
Does 'comments' mean the table 'comments'? And if you were comparing a variable with comments.id, would you have to include the variable outside of the single quotes like this: 'comments.id =' $blogid ?
Or can I do this: query from one table and put those results in a variable as follows:
$result1 = $this->db->get();
and then again do another query from the other table and put that in
$result2
Then I can say: $query = $result1 + $result2;
Is that possible?
If someone could please confirm this information/help me out I would be greatful. Thanks