Welcome Guest, Not a member yet? Register   Sign In
Fill dropdown from database
#2

[eluser]flaky[/eluser]
Code:
//model
class Some_model extends Model {
    
    public function __construct() {
        parent::__construct();
    }
    
    public function get_dropdown() {
        $result = $this->db->select('id, name')->get('table_name')->result_array();
        
        $list = array();
        foreach($result as $r)
            $list[$r['id']] = $r['name'];
            
        return $list;
    }
}

.
.
.
//controller

class Test extends Controller {
    
    public function __construct() {
        parent::__construct();
        
        //Load models
        $this->load->model('some_model');
    }
    
    public function index() {
        $data['dropdown'] = $this->some_model->get_dropdown();
        $this->load->view('some_view', $data);
    }

}

.
.
.
//View
Some dropdown: <?php echo form_dropdown('some_dropdown', $dropdown); ?>


Messages In This Thread
Fill dropdown from database - by El Forum - 09-08-2010, 05:17 AM
Fill dropdown from database - by El Forum - 09-08-2010, 06:22 AM
Fill dropdown from database - by El Forum - 09-08-2010, 09:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB