2013-11-25 55 views
0

对于我的应用程序,我需要从数据库中提取数据并相应地标记字段。我坚持如何根据取得的值标记单选按钮。我在分享我写的代码来获取数据和我需要检查的单选按钮。根据从mysql数据库中提取的值检查单选按钮

$Medical_Record_Id=$_SESSION['Medical_Record_Id']; 
$DOL=$_SESSION['DOL']; 
$hour=$_SESSION['hour']; 
$Question1="xxx"; 
$data1 = 'SELECT Option_Selected FROM Form1 WHERE Medical_Record = "'.$Medical_Record_Id.'" and DOL="'.$DOL.'" and hour="'.$hour.'" and Question="'.$Question1.'"' ; 
$query = mysql_query($data1) or die("Couldn't execute query. ". mysql_error()); 

的HTML代码,我有单选按钮是

<div> 
     <span> 
     <input type="radio" name="Gestational_age" class="field checkbox" value="<28" tabindex="7" /> 
     <label class="choice" for="Gestational_age"><28</label> 
     </span> 
     <span>  
     <input type="radio" name="Gestational_age" class="field checkbox" value="28-31" tabindex="7" /> 
     <label class="choice" for="Gestational_age">28-31</label> 
     </span> 
     <span>  
     <input type="radio" name="Gestational_age" class="field checkbox" value=">=32" tabindex="7" /> 
     <label class="choice" for="Gestational_age">>=32</label> 
     </span> 
     </div> 

请指导我如何检查基于我在$查询获取值的单选按钮。

回答

0

首先,你的HTML真的搞砸了。如果您想使用符号,如><在HTML属性值或文本在标签中显示,你应该把它们转换成相应的HTML实体,例如,&lt;&gt;

后,如果您需要为选择标记的值,你应该具体<input>控制使用checked属性:

<input type="radio" checked="checked" .... > 
0

为了显示你输入时检测放一些像下面,请参阅第二输入

<form> 
<input type="radio" name="Gestational_age" class="field checkbox" value="<28" tabindex="7"> 
<input type="radio" name="Gestational_age" class="field checkbox" value="28-31" tabindex="7" checked="checked"> 
<input type="radio" name="Gestational_age" class="field checkbox" value=">=32" tabindex="7"> 
</form> 
相关问题