CodeIgniter Forums
Dropdown default value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Dropdown default value (/showthread.php?tid=20653)



Dropdown default value - El Forum - 07-17-2009

[eluser]Ninja[/eluser]
Controller
Code:
$client = new Client();
            $client->get('id');
    
            foreach($client->all as $entry)
            {
                $clientID = $entry->id;
                $entry->company->get('companyname');
                $companyName = $entry->company->companyname;
                $data['parent'][$clientID] = $companyName;    
            }

View
Code:
<?php echo form_dropdown('Parent', $parent )?>

Im trying to set the default value for the dropdown to something like “Not Applicable”
With an index of 0. This dropdown is for Parent clients (ie. The client of a client) but not all clients will have a parent client.
I cant set the 3rd parameter to "Not Applicable" with index 0 because its not in the array. and i cant seem to add it to the array because the array is populated from a database table Clients which contains 3 fields:
id serial,
parent_client interger,
company_id,


Dropdown default value - El Forum - 07-17-2009

[eluser]Dam1an[/eluser]
Why could you not carry tis on in your other thread? Now you're going to get answers spread accrosss 2 threads which won't help anyone


Dropdown default value - El Forum - 07-17-2009

[eluser]Ninja[/eluser]
I was told to put it in this thread so i moved it


Dropdown default value - El Forum - 07-17-2009

[eluser]Ninja[/eluser]
Anyway i found a solution to this problem I just needed to add the extra elament to the array like such

Controller
Code:
$data['parent'][0] = 'Not Applicable';
            foreach($client->all as $entry)
            {
                $clientID = $entry->company_id;
                $entry->company->get('companyname');
                $companyName = $entry->company->companyname;
                $data['parent'][$clientID] = $companyName;    
            }


Thanx to everyone who helped it is highly appreciated