Welcome Guest, Not a member yet? Register   Sign In
how to create dynamic drop down
#1

[eluser]shades[/eluser]
im new to ci & enjoying it very much.
but i cant populate my drop down dynamically. i have controller that calls model where there get all() method. my dbtable has only 3 column they are id title & desc,
i want to populate form_dropdown in my view and it should display title & while submit it it should take id of selected title to my database. plz any one help me on this.
#2

[eluser]steelaz[/eluser]
In your controller load form helper, create array where key is "id" and value - "title" and pass this array to your view.

Code:
$this->load->helper('form');

$db_info = $this->your_model->get_info();

$dropdown = array();
foreach ($db_info)
{
    $dropdown[$db_info->id] = $db_info->title;
}

$this->load->view('your_view', array('dropdown' => $dropdown));

Then in your view you can use form helper's form_dropdown() function to render HTML for dropdown:

Code:
<?= form_dropdown('dropdown_name', $dropdown); ?>

http://ellislab.com/codeigniter/user-gui...elper.html




Theme © iAndrew 2016 - Forum software by © MyBB