网页下拉菜单的默认值
这可能解释起来很复杂。我建立了一个时间表系统,员工可以将他们自己的时间表记录插入到 mysql 数据库中。这工作正常,但我给了他们编辑他们插入的项目的选项,所以我有一个下拉列表,从 mysql 显示所有可供他们选择的项目编号,但我也想将下拉列表的默认值设置为他们在插入记录时选择的项目编号(即,为了避免记住它是什么项目),
这是我的代码:
$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>';
该记录存储在名为时间表的表中,因此我可以从中进行选择,但我'我不确定如何在上面的下拉列表中将正确的项目编号设置为默认值?
这有道理吗?
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)
here is my code:
$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>';
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?
Does that make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将项目编号存储在变量中,例如$projnum,并将其与每个值进行比较。
Store the project number in a variable, e.g., $projnum, and compare it with each value.
更改
为
Change
To