我想在递归表中创建一个选中的复选框基本ID,我有这样的表
+---------+--------------+-----------+
|user_id | function_id | feature_id|
+---------+--------------+-----------+
| 1 | 2 | 1 |
+---------+--------------+-----------+
| 1 | 2 | 2 |
+---------+--------------+-----------+
| 1 | 2 | 3 |
+---------+--------------+-----------+
然后使用foreach
复选框$feature = $this->db->get_where('my_table', array('function_id' => '2'))->result();
foreach ($result as $value)
{
$data = array(
'name' => 'feature_id',
'value' => $value->feature_id,
'checked' => // depend on feature_id if in function_id the feature id is exist then checked TRUE else FALSE
);
echo form_checkbox($data);
Plz帮助我! :(
答案 0 :(得分:1)
像这样更改您的PHP代码并告诉我。
$feature = $this->db->get_where('my_table', array('function_id' => '2'))->result();
foreach ($result as $value) {
$state = (!empty($value->feature_id)) ? TRUE : FALSE;
$data = array( 'name' => 'feature_id',
'value' => $value->feature_id,
'checked' => $state);
echo form_checkbox($data);
}
修改强>
如果您想显示所有checkboxs
,那么它必须位于foreach
循环中。