Bind data to dropdown in php

I am using codeigniter. I want to associate a table column with a drop down list.

+3
source share
1 answer
// 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 the easiest way to do this.

+3
source

Source: https://habr.com/ru/post/1788941/


All Articles