dongshiqin1352
2019-05-20 12:45
浏览 50
已采纳

从db中获取单选按钮值并且还要检查单选按钮[重复]

This question already has an answer here:

I have one radio button of gender. The value is getting stored in db and i am able to fetch it too. But I want the radio button to be checked for the received value. Help me.

    <input type="radio" name="gender" value="male" > Male
    <input type="radio" name="gender" value="female" checked> Female

</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 如何检查数据库,结果检查一个单选按钮? 3 answers

    I 有一个性别单选按钮。 该值将存储在db中,我也可以获取它。 但我希望检查单选按钮的接收值。 帮帮我。

     &lt; input type =“radio  “name =”gender“value =”male“&gt; 男性
     
    &lt; input type =“radio”name =“gender”value =“female”checked&gt; 女性  
     
      
     
      
     
     
     
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongyu1979 2019-05-20 12:53
    已采纳

    You can check which radiobutton should be selected by using if-else statement like below where $row['gender'] is column where radiobutton value is there :

        <?php  if($row['gender']== 'male') { ?>
    
        <input type="radio" name="gender" value="male" checked> Male
    
       <?php  }else { ?>
    
         <input type="radio" name="gender" value="female" checked> Female
    
       <?php } ?> 
    
    点赞 打赏 评论
  • douzhi4056 2019-05-20 12:53

    You can make it work as follow

    <?php
     $db_value = 'male'; // this is the value from db
    ?>
    <input type="radio" name="gender" value="male" <?php if($db_value == 'male'):?>checked<?php endif;?>> Male
    <input type="radio" name="gender" value="female" <?php if($db_value == 'female'):?>checked<?php endif;?>> Female
    
    点赞 打赏 评论

相关推荐 更多相似问题