CodeIgniter Forums

Full Version: From database to form_dropdown list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]piker[/eluser]
How to convert database query to
options i form_dropdown list ?

I always get array of array

I have
in controller
Code:
$data['options'] = $this->db->get('table');
$this->load->view('welcome_message',$data);


in views
Code:
<html>

<form>
<?=form_dropdown('bleble',$options);?>
</form>

</html>

Thanks
piker

El Forum

[eluser]gtech[/eluser]
Not sure what your database table contains.
Say you database table had a column tableid and tabledata you could try:

Code:
$dbres = $this->db->get('table');
$ddmenu = array();
foreach ($dbres->result_array() as $tablerow) {
  $ddmenu[$tablerow['tableid']] = $tablerow['tabledata'];
}
$data['options'] = $ddmenu;

$this->load->view('welcome_message',$data);

or


Code:
$dbres = $this->db->get('table');
$ddmenu = array();
foreach ($dbres->result_array() as $tablerow) {
  $ddmenu[] = $tablerow['tabledata'];
}
$data['options'] = $ddmenu;
$this->load->view('welcome_message',$data);

El Forum

[eluser]piker[/eluser]
It work !
Thanks

piker