php+mysql handles check box issues
PHP中文网
PHP中文网 2017-05-16 13:00:41
0
1
596

First of all, this is my project addition page

< /p>

After the project is added, I will change the submitted information into a string in the background
//When the form conditions are met, the project type will be converted into a string
$_POST['projecttype' ]=implode(',',I('post.projecttype'));
and then store it in the database,

Now I want to modify this data. The page looks like this

< /p>

How to make the previously added project types be checked by default when modifying, just like the project name can appear on the modification page

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
PHPzhong

In the template:

$selectedTypes = [1,3];
$options = ['1' => '移动APP', '2' => 'WEB', '3' => 'PC']; // ‘id’ => '名称'
foreach($options as $id => $label) {
    if (in_array($id, $selectedTypes)) {
        echo '<label><input type="checkbox" name="projecttype[]" value="'. $id .'" checked="checked">' . $label .'</label>';
    } else {
        echo '<label><input type="checkbox" name="projecttype[]" value="'. $id .'">' . $label .'</label>';
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template