0

我有 2 个查询。一个是填充一个填充下拉列表的数据集,另一个填充表格行的其余文本框。我想知道如何填充整个下拉列表,然后将 selectedvalue 设置为来自其他查询的值?

例如 -

dataset query = select hobby from hobbies
other query - select name, dob, address, hobby from employee

现在桌子看起来像这样 -

Name DOB         Address       Hobby
Sam  01/10/1988  111 main st   Dropdownlist(n number of records)

现在在下拉列表中,我希望将员工表中的所有爱好填充为所选值。

4

1 回答 1

1

不知道我是否理解,但我会尝试一些伪代码

  ## fetch hobbies and employees from db
  dataset hobbies = select hobby from hobbies;
  dataset employees = select name, dob, address, hobby from employee;

  ## loop through all employees
  foreach employee in employees{

    print employee->name;
    print employee->dob;
    print employee->adress;

    ## second loop to print hobbies dropdownlist for each emplyee
    print "<select>";
    foreach hobby in hobbies{
      boolean is_selected = (employee->hobby == hobby);
      print "<option value=\"".hobby."\" selected=\"".is_selected."\">".hobby."</option>";
    }
    print "</select>";
}

这不是正确的 html 或任何东西,只是证明概念的伪代码。

于 2010-03-09T19:45:45.727 回答