Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中编辑单选按钮的值_Php_Html - Fatal编程技术网

如何在php中编辑单选按钮的值

如何在php中编辑单选按钮的值,php,html,Php,Html,在php表单中,我从单选按钮到数据库获取数据。它工作得很好。但在编辑页面中,如何从数据库中获取检查值 我的代码是: <div class="data"> <div class="label1">PCDC:</div> <div style="text-align:right;width:49px;float:left;"> &l

在php表单中,我从单选按钮到数据库获取数据。它工作得很好。但在编辑页面中,如何从数据库中获取检查值

我的代码是:

             <div class="data">
                <div class="label1">PCDC:</div>
                <div style="text-align:right;width:49px;float:left;">
                <input type="radio" name="pcdc"  value="yes" style="vertical-align: middle; margin: 0px;">YES
                </div>
                <div style="text-align:right;width:46px;float:left;">

                <input type="radio" name="pcdc"  value="no" style="vertical-align: middle; margin: 0px;">NO
                   </div>
         </div>

PCDC:
对
不

请尝试这样的代码: 假设单选按钮值的变量名为“$val”,然后像那样使用这个$val变量

<input type="radio" name="pcdc" <?php if($val == 'yes') { echo "checked='checked'"; } ?>  value="yes" style="vertical-align: middle; margin: 0px;">YES
<input type="radio" name="pcdc"  <?php if($val == 'no') { echo "checked='checked'"; } ?> value="no" style="vertical-align: middle; margin: 0px;">NO

您可以尝试以下代码来

$('input[name="pcdc"][value="yes"]').prop('checked',true);

以上是一个jQuery解决方案,优点是当您有多个单选按钮时,无需检查每个元素。

php代码在哪里?一般问题,一般答案-您应该在编辑页面上添加“checked”属性-基于您获得的db值?发布您的编辑页面代码