我收到的所有來自數據庫的結果,並使用該查詢顯示一個DataTable他們在HTML徹底改變它如何通過1增加ID或使用PHP代碼
$result['getTableGroup'] = $this->getTableGroup();
return $this->load->view('users/index', $result);
,這裏是我的看法
代碼<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Group Users</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($getTableGroup as $value) : ?>
<tr>
<td>
<?= $value->group_name ?>
</td>
<td>
<?php if ($value->group_status == 'on'): ?>
<div class="switch">
<div class="onoffswitch">
<input type="checkbox" checked class="onoffswitch-checkbox" id="example1" name="group-status">
<label class="onoffswitch-label" for="example1">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<?php elseif ($value->group_status == 'off'): ?>
<div class="switch">
<div class="onoffswitch">
<input type="checkbox" checked class="onoffswitch-checkbox" id="example2" name="group-status">
<label class="onoffswitch-label" for="example2">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
代碼工作正常,問題是這裏使用onoff switch
現在這是一個列表,並在id IM input and label
將是相同的,所以這部分的代碼不工作正常我想要生成一些random numbers or loop
增加一個我可以把該變化器在id and label
因此每次每個<td>
運行,因此id
在標籤將更改,然後只有代碼將做工精細
<td>
<?php if ($value->group_status == 'on'): ?>
<div class="switch">
<div class="onoffswitch">
<input type="checkbox" checked class="onoffswitch-checkbox" id="example1" name="group-status">
<label class="onoffswitch-label" for="example1">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<?php elseif ($value->group_status == 'off'): ?>
<div class="switch">
<div class="onoffswitch">
<input type="checkbox" checked class="onoffswitch-checkbox" id="example2" name="group-status">
<label class="onoffswitch-label" for="example2">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<?php endif; ?>
</td>
我的建議是這樣的任務,總是重複鍵與值:'的foreach($改編爲$ k => $ V){//使用$ K表是基於零,但如果你需要一個自然順序,你可以輸出$ k + 1}'。 – Tpojka