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) { ?>

<?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>
4

3 回答 3

2

尝试更改<?to<?php$row_settings[Applied_Elsewhere]to$row_settings['Applied_Elsewhere']

于 2012-04-27T11:06:54.550 回答
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>
于 2012-04-27T11:32:11.767 回答
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>';
    ?>

于 2012-04-27T11:19:29.397 回答