Welcome Guest, Not a member yet? Register   Sign In
array to dropdown values
#1

[eluser]Mutsop[/eluser]
Hi,

I'm trying to get an array (retrieved from my database) to the values of my dropdown box.
Here is what I have:

controller:
Code:
$this->data['dropdown'] = array(
   $this->my_model->get_values(),
);

And this is my view:
Code:
<?php echo form_dropdown('dropdownname', $dropdown, 'some value');?>

My print_r is:
Quote:Array ( [0] => stdClass Object ( [id] => 1 [name] => value1 [description] => value1description ) [1] => stdClass Object ( [id] => 2 [name] => value2 [description] => value2description ) )

So How do I get the valuexdescription into my dropdown? As this is an array object and should be converted.... Don't really know how Sad Also, when the form should be submitted, the [name] should be passed not the desciption.
#2

[eluser]Atharva[/eluser]
Can't you just return the results from get_values function in this format
Code:
$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );

which will then serve as second parameter to form_dropdown ?
#3

[eluser]Mutsop[/eluser]
Well technically I can, but would like to know for futur use if possible Big Grin
As for now, it's a simple "privilege" selection box for users. So it shouldn't be dynamicly created.




Theme © iAndrew 2016 - Forum software by © MyBB