我将复选框中的值发布到用户配置文件的数据库中。当用户去编辑他/她的个人资料时,我希望他们之前选择的复选框被选中,这样他们就不会在更新他们的个人资料后丢失该信息。我尝试了许多不同的解决方案,但没有运气。
复选框值输入到表名 members_teachers 到名为 focus 的列中,并用逗号分隔,例如艺术、数学、舞蹈等或您可以提供的建议。非常感谢您提前
我尝试检查值的代码是
<?php
$focusQuery = mysql_query("SELECT focus FROM members_teachers WHERE id = $member_id") or die;
while ($new_row = mysql_fetch_assoc($focusQuery)){
$focusRow = $row['focus'];
$focusValue = explode(',', $focusRow);
foreach($focusValue as $newFocus){
//echo $newFocus;
//echo "<br/>";
$result = mysql_query("SELECT focus FROM members_teachers WHERE focus LIKE '%$focusRow%'") or die;
if(mysql_num_rows($result) > $newFocus){
$checked = 'checked="checked"';
}
else{
$checked = '';
}
}
}
?>
这是我的html
<label for="art-focus">Art</label>
<input name="focus[]" type="checkbox" value="Art" <?php echo $checked ?>>
<label for="math-focus">Mathematics</label>
<input name="focus[]" type="checkbox" value="Mathematics" <?php echo $checked ?>>
<label for="dance-focus">Dance</label>
<input name="focus[]" type="checkbox" value="Dance" <?php echo $checked ?>>