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
PHPz2017-05-16 13:02:41
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>';
}
}