2013-11-25 52 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> 
相關問題