1 回答
TA贡献1906条经验 获得超3个赞
在 foreach 语句中添加 next
$item['team_members'] = $this->mastertable_model->get_team_member($item['team_id']);
第二部分是你的观点:
<?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<?= $tname['team_id'];?>" type="text" data-id="<?php echo $tname['team_id'];?>"
name="teamname" value="<?php echo $tname['team_name'];?>"> <br/>
<table id="teammembertable" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Staff name</th>
<th>Staff type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $memb = json_decode(json_encode($tname['team_members']), True);
foreach($memb as $member){
if (!empty($member['Staff_name'])) { ?>
<tr>
<td class="teamstaff_member"><?= $member['Staff_name'];?></td>
<td class="teamstafftype_member"><?= $member['Staff_type']; ?></td>
<td class="teamstafftype_member"><?= $member['Action']; ?></td>
</tr>
<?php } else{ ?>
<tr>
<td></td>
<td>No records found.</td>
<td></td>
</tr>
<?php }} ?>
</tbody>
<tfoot>
<tr>
</tr>
</tfoot>
</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 } ?>
我看不到你完整的新 json,我已经将它用作数组,但是,如果它看起来像这样它应该可以正常工作,你将替换<?= $memb['blabla']?>为$memb->blabla:
$team_name = [
[
"team_id" => 1,
"team_name" => "Water tank clean",
"team_members" => [
[
"team_id" => 2,
"Staff_id" => 14,
"Staff_type" => "Leader",
"Staff_name" => "nimisha",
"Action" => "eat"
],
[
"team_id" => 2,
"Staff_id" => 15,
"Staff_type" => "Player",
"Staff_name" => "misha",
"Action" => "play"
]
]
],
[
"team_id" => 2,
"team_name" => "Water tank clean",
"team_members" => [
[
"team_id" => 2,
"Staff_id" => 14,
"Staff_type" => "Leader",
"Staff_name" => "nimisha",
"Action" => "eat"
],
[
"team_id" => 2,
"Staff_id" => 15,
"Staff_type" => "Player",
"Staff_name" => "misha",
"Action" => "play"
]
]
]
];
现在,我将尝试使其与您的 json 一起使用。
如果您将发送唯一的$cabangas$data怎么办?没有json_encode命令?做下一步,替换:
$this->load->view('team_memb_creation', $data);
在
$this->load->view('team_memb_creation', ['team_name' => $cabang]);
并使用我的版本。
二、
public function create_team_memb()
{
$data['team_name'] = $this->mastertable_model->get_team_name();
$data['selectallstaff'] = $this->mastertable_model->selectallstaff();
$cabang = array();
foreach($data['team_name']->result() as $list){
$item = array();
$item['team_id'] = $list->team_id;
$item['team_name'] = $list->team_name;
$item['team_members'] = $this->mastertable_model->get_team_member($item['team_id']);
array_push($cabang,$item);
}
$selectallstaff= json_decode(json_encode($data['selectallstaff']), True);
$this->load->view('team_memb_creation', [
'team_name' => $cabang,
'selectallstaff' => $selectallstaff
]);
}
看法
<select class="form-control" id="" name="">
<option value="">Select</option>
<?php
foreach($selectallstaff as $staffname)
{ ?>
<option value="<?= $staffname['Staff_id']; ?>"><?= $staffname['Staff_name']; ?></option>
<?php }
?>
</select>
- 1 回答
- 0 关注
- 161 浏览
添加回答
举报