如何检查同一ID在另一列中是否有多个值?

编程入门 行业动态 更新时间:2024-10-27 14:27:07
本文介绍了如何检查同一ID在另一列中是否有多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有团队成员表和团队表。 在team member table中,有3列是teamid,staff_id和stafftype(领导者或技术员)。一队只有一名领导者(staff_type列值)。因此,当我向团队成员表中插入数据时,我需要检查同一团队中是否有任何领导者。

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_id staff_id stafftype 1 2 leader 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"

模式

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'); } }

}

推荐答案

模型:

public function add_team_memb(){ $this->db->select('NEXT VALUE FOR team_seq as team_id'); $query = $this->db->get(); foreach ($query->result_array() as $row) { $team_id = $row['team_id']; } $this->db->select('*'); $this->db->from('team_member'); $querySS = $this->db->get()->result(); if(array_search('1', array_column($querySS, 'team_id')) !== false) { return 1; } else { $datateam_memb = array( 'team_id' => $team_id, 'staff_id' => 3, 'stafftype' => 'leader', ); $insert_id = 0; if ($this->db->insert("team_member", $datateam_memb)) { $insert_id = $this->db->insert_id(); } return $team_id; } }

控制器::

public function addteammember() { $value = $this->Admin_model->add_team_memb(); if($value == 1) { ///pass message in view leader is already in team } else { $this->load->view('team_memb_creation'); } }

更多推荐

如何检查同一ID在另一列中是否有多个值?

本文发布于:2023-10-26 11:08:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529956.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!