我有一個表格,每行有3列:名稱,啓用,禁用。啓用和禁用列有一個複選框和名稱狀態,我試圖做每行只有一個打勾的複選框。這些是我的代碼(每個行和兩列)爲止:每個行只檢查複選框
<?php foreach($customers as $customer):?>
<tr>
<td align="center"><?php echo $customer;?></td>
<?php
$check = FALSE;
if($user_customer != FALSE)
foreach($user_customer as $object)
foreach($object as $current_customer)
if($current_customer == $customer)
$check = TRUE;
?>
<td align='center'>
<?php
if($check == FALSE)
$data = array('name' => 'enable[]', 'value' => $customer, 'checked' => FALSE);
else
$data = array('name' => 'enable[]', 'value' => $customer, 'checked' => TRUE);
echo form_checkbox($data);
?>
</td>
<td align='center'>
<?php
if($check == TRUE)
$data = array('name' => 'disable[]', 'value' => $customer, 'checked' => FALSE);
else
$data = array('name' => 'disable[]', 'value' => $customer, 'checked' => TRUE);
echo form_checkbox($data);
?>
</td>
</tr>
<?php endforeach?>
後提交我的形式將相應的存儲值到數據庫中,但是我不希望用戶能夠打勾兩個複選框一次。我嘗試使用單選按鈕,但是每列只限於一次檢查。我正在嘗試使每行都有幫助?
P.S.我不喜歡使用任何Javascript。
編輯,我說的每一行計數器,因此這將是radio_1
第一行等,這是我編輯的部分:
<td align='center'>
<?php
if($check == FALSE)
$data = array('name' => "radio_$counter", 'value' => $customer, 'checked' => FALSE);
else
$data = array('name' => "radio_$counter", 'value' => $customer, 'checked' => TRUE);
echo form_radio($data);
?>
</td>
<td align='center'>
<?php
if($check == TRUE)
$data = array('name' => "radio_$counter", 'value' => $customer, 'checked' => FALSE);
else
$data = array('name' => "radio_$counter", 'value' => $customer, 'checked' => TRUE);
echo form_radio($data);
?>
</td>
EDIT 2,這是我如何用來檢索它在我的控制器功能:
// These were the arrays that I assigned to each checkbox according to the column
$enable = $this->input->post('enable');
$disable = $this->input->post('disable');
// I used it for inserting and deleting values
$insert = $this->home_model->insert_customer(array('user_id'=>$user_id, 'customer'=>$enable));
$delete = $this->home_model->delete_customer($user_id, $disable);
只能使用單選按鈕並在每行中更改其名稱。可能會使用一些計數器或數據庫ID。 –
@NiranjanNRaju我把名字改成了什麼?我使用了兩個複選框,因爲如果我使用了一個複選框,我也想獲得不確認的值,如果可能的話。 – hzq
第一行的單選按鈕名稱=> radio_1,第二行,radio_2 ...等 –