我有一个性别行,带有单选按钮男性&女。当我第一次注册时,单选按钮的值将存储在数据库中。现在我的问题是,如果我再次编辑该行,它想要来(这意味着已检查)该值为男/女。如何制作?
注意:使用php。
HTML脚本:
<label class="control-label" >Gender:</label>
<div class="row">
<div class="col-md-6" >
<label class="radio-inline" >
<input type="radio" name="gender" id="optradio" checked>Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" id="optradio">Female
</label>
</div>
</div>
答案 0 :(得分:2)
<label class="control-label" >Gender:</label>
<div class="row">
<div class="col-md-6" >
<label class="radio-inline">
<input type="radio" name="gender" value="Male" <?php if ($gender != "Female") echo "checked"; ?> />Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" value="Female" <?php if ($gender == "Female") echo "checked"; ?> />Female
</label>
</div>
</div>
我做了一些更正:
答案 1 :(得分:0)
要在显示表单时激活精确的单选按钮,您只需使用if block来显示结果For Eg:
<?php
$male="";
$female="";
//code to retireve data from your db
if($result['gender']=='male')
{
echo "<input type='radio' name='gender' id='optradio' checked> Male";
echo "<input type='radio' name='gender' id='optradio' >Female";
}
else
{
echo "<input type='radio' name='gender' id='optradio' > Male";
echo "<input type='radio' name='gender' id='optradio' checked>Female";
}
?>