php 如何在php的编辑页面中选中单选按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14301164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get checked radio button in edit page in php?
提问by SS Nath
In php form I get the data from radio button to database. It works well. But in edit page how do I get the checked value from database?
在 php 表单中,我从单选按钮获取数据到数据库。它运作良好。但是在编辑页面中如何从数据库中获取选中的值?
<td align="left" valign="middle"><input name="signi" type="radio" id="signi" value="S"/> YES
<input name="signi" type="radio" id="signi" value="N" /> No</td></td>
回答by J.K.A.
Do like this in your edit page:
在您的编辑页面中这样做:
Take database value in variable:
在变量中获取数据库值:
Example:
例子:
<?php $signi= $row['signi']; ?>
And :
和 :
<td align="left" valign="middle">
<input name="signi" type="radio" id="signi" value="S" <?php echo ($signi== 'Yes') ? "checked" : "" ; ?>/> YES
<input name="signi" type="radio" id="signi" value="N" <?php echo ($signi== 'No') ? "checked" : "" ; ?>/> No</td></td>
Check this thread for details:
检查此线程以获取详细信息:
回答by Vijay Maurya
Get the value of that radio button :
获取该单选按钮的值:
<?php $signi= $row['signi']; ?>
Then in HTML
然后在 HTML 中
<td align="left" valign="middle">
<input name="signi" type="radio" id="signi" value="S" <?php if($signi=='S'){ echo "checked=checked";} ?>/> YES
<input name="signi" type="radio" id="signi" value="N" <?php if($signi=='N'){ echo "checked=checked";} ?>/> No</td></td>
回答by Manoj Purohit
you have to check database value first and then set checked property to checked if true
您必须先检查数据库值,然后将检查属性设置为检查是否为真
<input name="signi" type="radio" id="signi" value="S" <?php if($row["signi"]=="S"){echo "checked=\"checked\" "} ?> />`
回答by Muhammad Raheel
You can do it like this.
when you fetch record from table you will be outputting the other data on the form. Let suppose $rowis a php variable which contains the record.
你可以这样做。当您从表中获取记录时,您将在表单上输出其他数据。假设$row是一个包含记录的 php 变量。
if($row['checkboxfieldname'] == 'my required condition'){
?> <input type = 'checkbox' value = '1' name = 'blahblah' checked> <?
}else{
?> <input type = 'checkbox' value = '1' name = 'blahblah'> <?
}

