www.webdeveloper.com
Results 1 to 2 of 2

Thread: Complex arrays

  1. #1
    Join Date
    Nov 2002
    Location
    Peterborough, UK
    Posts
    166

    Complex arrays

    I think the answer to this is probably quite simple, but I can't find a sample of similar code. Maybe there is a better way of doing what I want.

    I would like a form with two <SELECT> lists.

    The first list includes company names. The company names are stored in an array.

    The second list includes employee names. The employee names are also in an array. My first questio: it it possible to give the employee array 2 indexes (indices!?), the first being company and the second being the employee. I guess I would reference the array like this ....

    $employee = emparray[0][0];
    $employee2 = emparray[0][1];
    $employeex = emparray[2][1]; etc

    How do I build such an array?

    The contents of my drop-down lists will be fetched from a database by my PHP code. I'm guessing that I will need my PHP code to dynamically build these arrays.

    Anyone with a suggestion for a better method feel free to say.

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    I would not go with 2d array for this task but rather with objects:
    Code:
    
    //declaration
    function emloyee(firstName,lastName)
    { this.firstName = firstName;
      this.lastName = lastName;
    }
    
    function.company(employees)
    { this.employees = employees;
    }
    
    //initialization
    company1 = new company (new Array(
    new employee('Tom','Smith'),
    new employee('Bill','Jackson'),
    ....
    new employee('Steve','Simpson')));
    
    company2 = ...
    
    companies = new Array(company1,company2,...);
    
    

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles