0

我在这里有这部分,我用它来打印列表中的一些值:

<select id = "paisja" name="paisja" >
<?php
while( $row = odbc_fetch_array($resultpaisja) ) {
?>

 <option value="<?php echo $row['id_paisje']; ?>"><?php echo $row['paisje']; ?></option>
<?php
}
?>

现在,我需要的是,如果我打印此订单的列表,该列表应该会再次出现,但带有选定的值......请帮忙?谢谢

4

3 回答 3

0

您可以尝试使用 post 方法从所选索引中获取值

例子:

    echo '<select name="paisja">';
    while( $row = odbc_fetch_array($resultpaisja))
    {
        echo'<option value="'. $row["id_paisje"] .'">' . $row["paisje"] . '</option>';
    }
   echo '</select><br />';



    echo $_POST['paisja']; //will output the selected value
于 2013-03-04T08:49:01.763 回答
0

只需注意选择选项中添加的 PHP 代码块。[更新]

<select id = "paisja" name="paisja" >
<?php while( $row = odbc_fetch_array($resultpaisja) ) {

$default_select_id = 1; //Set a default ID

if(isset($_REQUEST['paisja']) && $_REQUEST['paisja'] == $row['id_paisje']){ 
  $select = ' selected="selected" '; //Set from submitted value
} elseif ($row['id_paisje'] == $default_select_id) {
  $select = ' selected="selected" ';  //Set from default ID if no submitted value
}

?>
 <option value="<?php echo $row['id_paisje']; ?>"  <?php echo $select; //Execute the selection ?> >
<?php echo $row['paisje']; ?>
</option>
<?php
}

?>
于 2013-03-04T09:27:11.017 回答
0

尝试这个 :

<option <?php if(isset($_REQUEST['paisja']) && $_REQUEST['paisja'] == $row['id_paisje']){?>selected="selected"<?php } ?> value="<?php echo $row['id_paisje']; ?>"><?php echo $row['paisje']; ?></option>

添加 :<?php if(isset($_REQUEST['paisja']) && $_REQUEST['paisja'] == $row['id_paisje']){?>selected="selected"<?php } ?>在选项标签中。

于 2013-03-04T08:35:51.153 回答