#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    28
    Rep Power
    0

    Multidimensional Array as Checkbox Value


    I have a nested repeat region in a PHP Page which displays something like this:

    Line Manager Name
    Employee Name
    City
    City
    City
    Line Manager Name
    Employee Name
    City
    City
    City

    Each of the above have their own ID value pulled from a MySQL Database. Under the Employee Name is a list of Cities, again with an ID. Alongside each of the cities is a checkbox. What I need to be able to do is pass through all three ID's (Line Manager, Employee and City) as an array as the value for an individual checkbox.

    I think I understand that the checkbox needs to be defines as something like:

    Code:
    <input name="$arr_values[][][]" type="checkbox" id="$arr_values[][][]" value="" />
    But, as you can see I can't figure out how to assign the three values to each element of the array.

    I want to end up with:
    $arr_values[line_mgr_id][employee_id][city_id]

    Can anyone help??

    Simon
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2008
    Location
    North Carolina
    Posts
    2,674
    Rep Power
    2674
    Assuming your loop looks something like this, its as simple as echo-ing the variable.

    PHP Code:
    <?
    while ($row mysql_fetch_assoc($result)){ // line managers
        
    $manager_id $row['manager_id'];
        
    $manager_name $row['manager_name'];
        
    $employee_id $row['employee_id'];
        
    $employee_name $row['employee_name'];

        echo 
    $manager_name,'<br />',str_repeat('&nbsp;'4),$employee_name,'<br />';

        
    mysql_data_seek($result20); // since this result will be used more than once
        
    while ($cities mysql_fetch_assoc($result2)){ // cities
            
    $city_id $cities['id'];
            
    $city_name $cities['name'];

            echo 
    str_repeat('&nbsp;'8),"<input type=\"checkbox\" name=\"$values[$manager_id][$employee_id][]\" id=\"$manager_id-$employee_id-$city_id\" value=\"$city_id\" /> $city_name<br />\n";
        }
    }
    ?>

IMN logo majestic logo threadwatch logo seochat tools logo