Trying to populate a dropdown menu in codeigniter with mysql data

后端 未结 1 1885
别跟我提以往
别跟我提以往 2021-01-29 02:23

Im trying to populate a dropdown box on a registraton form in code igniter but i have had not luck below are snippets from my contorller, model, and view. Base is the drop down

1条回答
  •  囚心锁ツ
    2021-01-29 02:43

    Your format should be like this:

    $options = array(
                      'small'  => 'Small Shirt',
                      'med'    => 'Medium Shirt',
                      'large'   => 'Large Shirt',
                      'xlarge' => 'Extra Large Shirt',
                    );
    
    $shirts_on_sale = array('small', 'large');
    
    echo form_dropdown('shirts', $options, 'large');
    

    this would produce:

    
    

    REFER HERE


    UPDATE

    you could also try this if you want

    MODEL

    $this->db->select('airport_code, airport_name');
    $this->db->order_by('airport_code', "asc");
    $query = $this->db->get('airports');
    if($query)
    {
        $query = $query->result_array();
        return $query;
    }
    

    CONTROLLER

    $query = $this->your_model->your_method();
    if($query)
    {
        $data['myDropdown'] = $query;
        $this->load->view('your_view', $data);
    }
    

    VIEW - YOUR DROPDOWN PROBLEM

    
    

    0 讨论(0)
提交回复
热议问题