编辑时选择的项目下拉菜单 [英] selected item ind dropdown when editing

查看:75
本文介绍了编辑时选择的项目下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

<select name="group">
    <option value="">Choose a group....</option>
    <?php foreach($groups as $group):?>
        <option value="<?php echo $group['groupID']?>" selected="yes"><?php      echo     $group['name']?></option>

    <?php endforeach;?>
</select>

我的问题是如何在我的下拉列表中编写选项标签,以便在我编辑现有数据,我将编辑的数据的选定组(管理员,用户,主持人)将在我编辑it.thanks时出现。

my question is how would i code the 'option' tag in my dropdown so that when i edit an existing data, the selected group(admin, users, moderators) of the data i will be editing will appear when i edit it.thanks.

推荐答案

选项标签的selected =yesHTML属性应该只有一个。您需要将其放在正确的组中。

The selected="yes" HTML attribute of the option tag should be only one. You need to put it on the right group.

设置像$ selected_group这样的PHP变量,如果组是正确的组,则为true,并且仅为那个小组。
将其设置为false。

Set a PHP variable like $selected_group that is true if the group is the right one, and print the selected attribute only for that group. Set it to false instead.

例如,如果您选择的组ID被设置为一个名为groupID的请求参数,则应使用以下代码: p>

For example, if your selected group id is putted as a request parameter called groupID you should use the code below:

<select name="group">
    <option value="">Choose a group....</option>
    <?php foreach($groups as $group):?>
    <?php if ($group['groupID'] == $_REQUEST['groupID']) $selected_group = true; else $selected_group = false; ?>
        <option value="<?php echo $group['groupID']?>" <? if ($selected_group) echo 'selected="yes"'; ?>><?php      echo     $group['name']?></option>

    <?php endforeach;?>
</select>

您可以将选择的groupid设置为$ groups中的数组成员,例如:

You could set the chosen groupid as a array member inside $groups, for example:

$groups[0]['selected'] = true;

在这种情况下,如下所示更改循环中的行:

In this case change the line inside the loop like this one:

<?php if ($group['selected']) $selected_group = true; else $selected_group = false; ?>

这篇关于编辑时选择的项目下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆