我有团队成员表和团队表。在团队成员表中有,三列有teamid、staff_id和stafftype(领导或技术员)。只有一名领导(staff_type 列值)会出现在一个团队中。因此,当我将数据插入团队成员表时,我需要检查同一团队中是否有任何领导者。
如何显示“该团队中已有领导者”的错误信息?团队成员表如下所示,
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
尝试从前端保存时,需要显示错误消息,即;“该团队已经有领导者”
莫代尔
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();
}
}
}
控制器
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');
}
}
}
幕布斯6054654