我使用复选框来获取和存储用户的兴趣。PHP - MySql:如何使用其他选项存储和检索复选框值
存储这些数据在mysql数据库与逗号分隔
我的PHP代码retrive这些数据,并显示在HTML页面
<?php
....
// Get data
$result = profile($uname);
$result['interest'] = explode(',', $result['interest']);
print_r($result['interest']); // output: Array ([0] => option1 [1] => option2 [2] => option3)
?>
....
<div class="col-sm-6">
<div class="form-check checkbox-style">
<label class="label-weight">Interests</label><br>
<label class="form-check-label label-weight">
<input type="checkbox" class="form-check-input" name="interest[]" onclick="return interest_validate(this);" id="selectall"><span class="check-label-pad"> Select all</span></label></label><label for="" class="opacity-set label-set" id="select-label"></label><br>
<label class="form-check-label label-weight">
<input type="checkbox" class="form-check-input" name="interest[]" onclick="return option_select(this);" value="option1" <?php echo in_array('option1',$result['interest']) ? 'checked' : ''; ?>><span class="check-label-pad">Option 1</span></label><br>
<label class="form-check-label label-weight">
<input type="checkbox" class="form-check-input" name="interest[]" onclick="return option_select(this);" value="option2" <?php echo in_array('option2', $result['interest']) ? 'checked' : ''; ?>><span class="check-label-pad">Option 2</span></label><br>
<label class="form-check-label label-weight">
<input type="checkbox" class="form-check-input" name="interest[]" onclick="return option_select(this);" value="option3" <?php echo in_array('option3', $result['interest']) ? 'checked' : ''; ?>><span class="check-label-pad">Option 3</span></label><br>
<label class="form-check-label label-weight">
<input type="checkbox" class="form-check-input" name="interest[]" id="other_checkbox" onclick=" return other_validate(this);" value="other"><span class="check-label-pad" >Other</span> </label><input type="text " class="text-style-other opacity-set" id="other-text" onblur="return other_text_validate();" />
<label for="" class="opacity-set label-set" id="other-text-label"></label>
</div>
</div>
问题:在编辑模式下,我使用“in_array()”按照数据库值将默认值选中复选框。但如何检查 “其他”(检查附加图像)选项并显示它的值?其中 条件我需要在这里添加?如何在一个领域的“利息” 存储在数据库
结果是什么print_r($ result)? – paranoid
在你的表格中有第二行的“other”。那么用户填写的复选框或文本框的值是多少? –
@paranoid,更新了问题。请检查 –