i have team member table and team table. In team member table have , three columns are there teamid, staff_id and stafftype(leader or technician). Only one leader (staff_type column value) will comes in one team. So when i insert data to team member table i need to check whether any leader is there in same team.
How to show an error message that "already have leader in this team"?Team member table looks like,
team_id staff_id stafftype
1 2 leader //see here already have leader for team_id 1
2 1 other
3 8 other
1 5 Technician
2 3 Other
1 4 Leader //This should not come. becoz already teamid-1 have Leader
When trying to save from frond end, need to show error message ie;"already have leader in this team"
MODAL
public function addteam_memb($datas) {
$this->db->select('*');
$this->db->from('team_members');
$querySS = $this->db->get()->result();
if(array_search('1', array_column($querySS, 'team_id')) !== false) {
return 1;
}
else {
$insert_id = 0;
if ( ! empty($datas)) {
$this->db->insert('team_members', $datas);
$insert_id = $this->db->insert_id();
}
}
}
CONTROLLER
public function editteammember() {
$getaddstafftype = $this->input->post( 'getaddstafftype' );
$getaddstaffname = $this->input->post( 'getaddstaffname' );
$getteamid = $this->input->post('getteamid');
$getstatus = $this->input->post('getstatus');
//if ( ! empty($getaddstaffname) )
if ( ! empty($getaddstaffname) && ! empty($getaddstafftype) ) {
foreach ($getaddstaffname as $key => $value ){
$data['Staff_id'] = $value;
$data['Staff_type'] = $getaddstafftype[$key];
$data['team_id'] = $getteamid[$key];
$data['status'] = "active";
$value = $this->mastertable_model->addteam_memb($data);
}
if($value == 1) {
echo "Already have leader in this team";
} else {
//$this->load->view('team_memb_creation');
}
}
}