Page 1 of 1

Making Dropdown boxes from array.

Posted: Mon Jul 14, 2008 12:18 pm
by dast
I have a load of the array entries below, what I need to know is how to loop through them making the 'internal name' the id for a select box and the 'options' the options for the select box. Any help would be greatly appreciated!!

Code: Select all

                                                       $data['profile:details'][] = (object)(array(
                                                                    "name" => __gettext("Are you circumsized? "),
                                                                    "internal_name" => "circumsized",
                                                                    "field_type" => "select",
                                                                    "options" => array(
                                                                        'yes'=>__gettext('Yes'),
                                                                        'no'=>__gettext('No'),
                                                                        'na'=>__gettext('Not Applicable')),
                                                                    "description" =>"",
                                                                    "user_type" => "person",
                                                                    "category" => __gettext("Your Personal Information"),
                                                                    "col1" => true,     
                                                                    "invisible" => false,
                                                                    "required" => false,
                                                                    ));
                                                                    
                                                                    
                                                        $data['profile:details'][] = (object)(array(
                                                                    "name" => __gettext("What type of body hair do you have?"),
                                                                    "internal_name" => "body_hair",
                                                                    "field_type" => "select",
                                                                    "options" => array(
                                                                        'yes'=>__gettext('Yes'),
                                                                        'no'=>__gettext('No'),
                                                                        'na'=>__gettext('Not Applicable')),
                                                                    "description" =>"",
                                                                    "user_type" => "person",
                                                                    "category" => __gettext("Your Personal Information"),
                                                                    "col1" => true,     
                                                                    "invisible" => false,
                                                                    "required" => false,
                                                                    ));

Re: Making Dropdown boxes from array.

Posted: Tue Jul 15, 2008 2:07 am
by sureshmaharana
Check this one:

$data['profile:details'][] = (object)(array(
"name" =>"Are you circumsized? ",
"internal_name" => "circumsized",
"field_type" => "select",
"options" => array(
'yes'=>'Yes',
'no'=>'No',
'na'=>'Not Applicable'),
"description" =>"",
"user_type" => "person",
"category" => "Your Personal Information",
"col1" => true,
"invisible" => false,
"required" => false,
));

$data['profile:details'][] = (object)(array(
"name" =>"What type of body hair do you have?",
"internal_name" => "body_hair",
"field_type" => "select",
"options" => array(
'yes'=>'Yes',
'no'=>'No',
'na'=>'Not Applicable'),
"description" =>"",
"user_type" => "person",
"category" => "Your Personal Information",
"col1" => true,
"invisible" => false,
"required" => false,
));





while (list($key, $val) = each($data['profile:details']))
{
?>
<select size="1" name="D1" style="width: 140; height: 22" id="<?=$data['profile:details'][$key]->internal_name;?>">
<?
while (list($optionkey, $optionval) = each($data['profile:details'][$key]->options))
{
?>
<option value="<?=$optionkey?>"><?=$optionval?></option>
<?
}
?>
</select>
<?
}