我的文本框显示了数据库中正确字段中的数据,但是当它是下拉列表时(选择)
我试过这段代码
<?php
$rs_settings = mysql_query("SELECT * from thesis WHERE user_id = $user_id;");
?>
<form action="academic.php" method="post" name="regForm" id="regForm" >
<?php
$num_rows = mysql_num_rows($rs_settings);
if($num_rows > 0) { ?>
<?php while ($row_settings = mysql_fetch_array($rs_settings)) {?>
1a.question <span
class="required">*</span></td>
<select name="Applied_Elsewhere" id="Applied_Elsewhere" >
<option <? if ($row_settings[Applied_Elsewhere]=='Y') { ?> selected <? } ?>
value="Y">Yes </option>
option <? if ($row_settings[Applied_Elsewhere]=='N') { ?> selected <? } ?>
value="N">No </option>
</select>
答案 0 :(得分:2)
尝试将<?
更改为<?php
,将$row_settings[Applied_Elsewhere]
更改为$row_settings['Applied_Elsewhere']
答案 1 :(得分:0)
请尝试以下代码:
<?php
$rs_settings = mysql_query("SELECT * from thesis WHERE user_id = $user_id;");
?>
<form action="academic.php" method="post" name="regForm" id="regForm" >
<?php
$num_rows = mysql_num_rows($rs_settings);
if($num_rows > 0) {
while ($row_settings = mysql_fetch_array($rs_settings)) {
1a.question <span
class="required">*</span></td>
print'<select name="Applied_Elsewhere" id="Applied_Elsewhere" >'
if ($row_settings['Applied_Elsewhere']=='Y')
print '<option value="Y" selected>Yes </option>';
else
if ($row_settings['Applied_Elsewhere']=='N')
print '<option value="N" selected>No</option>';
?>
答案 2 :(得分:0)
<select name="Applied_Elsewhere" id="Applied_Elsewhere" >
<option <?php if($row_settings['Applied_Elsewhere']=='Y') { echo "selected='selected'"; } ?> value="Y">Yes </option>
<option <?php if($row_settings['Applied_Elsewhere']=='N') { echo "selected='selected'"; } ?> value="N">No </option>
</select>