在代码点火器中显示选中的复选框基本递归 ID


Show checked checkbox base recursive ID in Codeigniter

我想在递归表中创建一个选中的复选框基本 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);

请帮帮我! :(

像这样更改您的 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循环中。