0

我有以下代码,它将必要的数据完美地插入数据库。但问题是,当我想实现 select="select".. 这样如果客户返回,他将看到他从下拉菜单中选择的内容......我该怎么做,任何想法......

<pre>
<?php
//array generated from mysql to feed first dropdown menu.
$newOptions = array();
    foreach ($input as $option) {
        $wclID = $option['desc'];
        $nameF = $option['fame'];
        $nameL = $option['lname'];
        $id = $option['ID'];
        $newOptions[$wclID][$id] = $nameL." ".$nameF;
    }

//second array for second dropdown menu
$array = array('ent','res');    
?>


   <div class="control-group">
        <div class="controls">
            <form  id="checkEnt" name="che" method="post" action="com.php?ID=<?=$ID?>">
                <input type="hidden" value="che" name="ent">
                <table class="table table-striped span10">
                    <tbody>
                        <? foreach ($newOptions as $wclID => $list) {  ?>
                            <tr><td width="5%">
                                    <h5><?=$wclID?> AA</h5>
                                </td>
                                <td width="10%">
                                    <label class="control-label" for="inputWei"><?=_('Boy')?></label>  
                                    <select class="input-xlarge" id="input" name="drop[0][]">   
                                        <option value=""><?=_('[select]')?></option>
                                        <?php 
                                            foreach ($list as $key => $value) {
                                            ?><option value="<?=$key?>"><?=$value?></option>

                                            <?php    } ?>
                                    </select>
                                </td>
                                <td width="10%">
                                    <label class="control-label" for="inputWei"><?=_('Res')?></label>
                                    <select class="input-xlarge" id="drop" name="drop[1][]">
                                        <option value=""><?=_('[select]')?></option>
                                        <?php
                                         foreach ($array as $key => $value) {
                                            ?><option value="<?=$value?>"><?=$value?></option>

                                            <?php } ?>
                                    </select>
                                </td>
                            </tr>

                              <?
                            }
                        ?> 

                            <tr><td colspan="3">
                                    <div class="modal-footer">
                                        <button type=reset class="btn btn-danger"><?=_('Reset')?></button>
                                        <button class="btn btn-primary" ID="btnSave"><?=_('Save')?></button>
                                    </div>
                                </td>
                            </tr> 


                    </tbody>
                </table> 
            </form>   
        </div>
    </div>
</pre>
4

2 回答 2

2

我最近做了类似的事情。这是针对从数据库返回的数据正确的吗?如果是这样,那么我将实现与此类似的东西。

在选项标签上,我会尝试使用 if 语句来查看数据库中的内容,然后调用 selected=selected

<option value="Something" <? if(in_array('Something',$nameofArray)) echo 'selected="selected"';?>>Something</option>

或者在您的情况下,您可能想尝试

<?foreach ($list as $key => $value) {?>
    <option value="$value" <? if($value) echo 'selected="selected"';?>>$value</option>

 <?}?>
于 2013-07-23T15:40:32.767 回答
-1

使用选项标签的“选定”属性:

http://www.w3schools.com/tags/att_option_selected.asp

于 2013-07-23T15:34:59.447 回答