//check the sub_teams that the user is assigned
$uid = $this->session->userdata('uid');
$this->db->select('sub_teams');
$this->db->from('users');
$this->db->where('uid', $uid);
$sub_teams_query = $this->db->get();
$sub_teams_result = $sub_teams_query->row();
$sub_teams = explode(',', $sub_teams_result->sub_teams);
check announcements that are active
$this->db->limit($limit, $start);
$this->db->select('*');
$this->db->from('announcements');
$this->db->where('active', 1);
$this->db->where('date_created <', date('Y-m-d H:m:s')); //hide the announcements that are new and not published yet.
//use foreach to use $this->$db->like with every sub_team that the user is assigned to
foreach ($sub_teams as $sub_team) {
$this->db->like('sub_teams', $sub_team);
echo $sub_team;
}
//users.id and //announcements.uid is joined to see who created the announcement and to get the user details of the person who created the announcement
$this->db->join('users', 'users.uid = announcements.uid');
$this->db->order_by('date_created', 'desc', 'after');
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;