views:

41

answers:

1

I have 2 queries. One is populating a dataset that populates the dropdownlist and the other populates rest of the textboxes of a table row. i want to know how can i fill the entire dropdownlist and then make selectedvalue the value from the other query?

e.g -

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

now the table looks like this -

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

Now in the dropdownlist I want all the hobbies populated with the hobby in the employee table to be the selected value.

+1  A: 

Not sure if i understood, but ill try with some pseudo-code

  ## 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>";
}

This is not correct html or anything, just a pseudocode to proof concept.

PHP_Jedi