[eluser]RMinor[/eluser]
After more research I was able to come up with a solution. Here it is and hopefully it can help someone else. If anybody sees anything wrong with it or can improve upon it feel free to let me know.
Code:
public function friends_of_friends($profile_id, $member_id) {
// Subquery #1
$this->db->select('profiles.id')
->from('profiles')
->join('friends', 'friends.to_id = profiles.id OR friends.from_id = profiles.id', 'left')
->where('(to_id = ' . $profile_id . ' OR from_id = ' . $profile_id . ')')
->where('profiles.id !=', $profile_id)
->where('friends.status', 'approved');
$first_where_clause = $this->db->get_compiled_select();
// Subquery #2
$this->db->select('profiles.id')
->from('profiles')
->join('friends', 'friends.to_id = profiles.id OR friends.from_id = profiles.id', 'left')
->where('(to_id = ' . $member_id . ' OR from_id = ' . $member_id . ')')
->where('profiles.id !=', $member_id)
->where('friends.status', 'approved');
$second_where_clause = $this->db->get_compiled_select();
// Main query
$this->db->select('COUNT(*) AS count')
->from('profiles')
->where('profiles.id IN (' . $first_where_clause . ')', null, false)
->where('profiles.id IN (' . $second_where_clause . ')', null, false);
$query = $this->db->get();
return ($query->num_rows() > 0) ? $query->result() : false;
}
A quick note, I had to add a method to the system/database/DB_active_rec.php file in order for my query to work. That method is below.
Code:
public function get_compiled_select($table = '', $reset = TRUE) {
if ($table != '') {
$this->_track_aliases($table);
$this->from($table);
}
$select = $this->_compile_select();
if ($reset === TRUE) {
$this->_reset_select();
}
return $select;
}