网页下拉菜单的默认值 [英] default value of dropdown on webpage

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

问题描述

这可能很复杂。我设置了一个时间表系统,员工可以在自己的时间表记录中插入一个mysql数据库。这很好,但是我已经给了他们编辑他们插入的项目的选项,所以我有一个下拉列表显示从mysql所有项目号码可供他们选择,但我也想设置下拉列表的默认值他们在插入记录时选择的项目号码(即避免不必记住什么项目)

This may be complicated to explain. I have set up a timesheet system where employees can insert into a mysql db their own timesheet records. this works fine but i've given them the option to edit an item they have inserted, so what i have is a dropdown displaying from mysql all project numbers available for them to pick but i also want to set the default value of the dropdown to the project number which they selected when they inserted the record (ie. to avoid having to remember what project it was)

这里是我的代码:

$result1 = mysql_query("select project_no from `projects`") or die(mysql_error());
            echo '<select name="project" class="project">';
        while($row1 = mysql_fetch_array($result1)){
            echo "<option selected='yes' value=".$row1['project_no'].">".$row1['project_no']."</option>";
        }
            echo '</select>';

记录存储在一个名为timesheets的表中,所以我可以从中做一个SELECT, m不知道如何在上面的下拉菜单中设置正确的项目号作为默认值?

The record is stored in a table called timesheets, so i can do a SELECT from that but i'm not sure how to set the right project number as the default value in the above dropdown?

这是否有意义?

推荐答案

将项目编号存储在变量中,例如$ projnum,并将其与每个值进行比较。

Store the project number in a variable, e.g., $projnum, and compare it with each value.

$result1 = mysql_query("select project_no from `projects`") or die(mysql_error());
            echo '<select name="project" class="project">';
        while($row1 = mysql_fetch_array($result1)){
            echo "<option ";
            if ($row1['project_no'] == $projnum) { echo 'selected="selected"; }
            echo " value=".$row1['project_no'].">".$row1['project_no']."</option>";
        }
            echo '</select>';

这篇关于网页下拉菜单的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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