Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bind data with dropdownlistbox in php

I am using codeigniter. I want to bind the column of my table with dropdownlistbox.

like image 598
enthusiastic Avatar asked Jun 25 '26 14:06

enthusiastic


1 Answers

// your controller
function index() {
    $result = $this->your_model->get_list();

    foreach ($result as $country)
    {
        $countries[$country->id] = $country->name;
    }

    $data['countries'] = $countries;
    $this->load->view('your_view', $data);
}

//your model
function get_list() {
   return $this->db->get('countries');
}

// your view
echo form_dropdown('country', $countries);

This is practically the easiest way to do this.

like image 84
Teej Avatar answered Jun 28 '26 04:06

Teej