enter image description here 我有三个表team,team_members和staff表。页面加载中显示团队名称。所以在这里我需要显示所有属于Team的团队成员名称。获取所有团队成员的名称都属于Team name.So只获取加载页面上的团队名称。如何从团队成员表中选择团队成员名称?
数据库表看起来像
team member table like
team_id staff_id staff_type
2 14 Leader
2 15 Other
3 11 Other
3 9 Leader
Staff table look like
staff_id staff_name status
14 xyz active
15 abc active
11 qwe active
9 opm active
预期
Team name 2
Staffname stafftype action
xyz Leader Delete
abc Other Delete
Team Name 3
Staffname stafftype action
qwe Other Delete
opm Leader Delete
<?php if(!empty($team_name)){ foreach($team_name as $tname){?>
<div class="content">
<form id="jobteam" name="jobteam[]" action="#" data-id="<?php echo $tname->team_id;?>" role="form" autocomplete="off">
<div class="row">
<div class="col-md-12">
<div class="card card-user">
<div class="card-header">
<h4 class="dropdate headteam<?php echo $tname->team_id;?>"><?php echo $tname->team_name;?></h4>
<div class="form-group row">
<label for="TeamName" class="col-sm-2 col-form-label cdropdate">Team Name</label>
<div class="col-sm-10">
<input class="form-control cdropdate teamname"
id="teamname<?php echo $tname->team_id;?>" type="text" data-id="<?php echo $tname->team_id;?>"
name="teamname" value="<?php echo $tname->team_name;?>"> <br/>
<table id="tblItems" class="tblItems">
<thead>
<tr>
<th>Staff Name</th>
<th>Staff Type</th>
<th>Action</th>
</tr>
</thead>
</table>
<div id="container-fluid" class="float-right">
<!-- for contract update button -->
<div class="">
<button type="button" id="saveteammembers" class="btn btn-success saveteammembers cdropdate">Save</button>
<!-- <button type="button" id="backto_headcontract" class="btn btn-success">Back</button>-->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<?php } } else{ ?>
<p>No records found.</p>
<?php } ?>
控制器
public function create_team_memb()
{
$data['team_name'] = $this->mastertable_model->get_team_name();
$this->load->view('team_memb_creation', $data);
}
模式
public function get_team_name() {
$this->db->select('team_id, team_name, status');
$this->db->from('team');
$this->db->where('status', 'active');
$query = $this->db->get();
return $query->result();
}