CodeIgniter Forums
multiple joins help! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: multiple joins help! (/showthread.php?tid=47383)



multiple joins help! - El Forum - 12-06-2011

[eluser]Unknown[/eluser]
I have 3 tables:

1. taskcategories (category_id, task_id) <-- this is a lookup table
2. categories (id, name) <-- this table lists all of my sites categories
3. tasks (id, description) <-- main table with tasks

I would like to retrieve all of the tasks that have the same category as my current task. My current task category is being passed into the function (see below).

I can't get it working.

Code:
function get_similar_tasks($category_id) {
  return $this->db->select('task_id')
    ->from('taskcategories')
    ->where('category_id', $category_id)
//join tasks table where taskcategories.task_id=tasks.id
    ->get()->result();
}