-4

有没有办法使用 CodeIgniter 中的表单助手创建 MySQL 链接下拉菜单?我试图做到这一点,但我似乎无法让它发挥作用。

模型

function get_airports()
    {
        $this->db->select('airport_code, airport_name');
        $this->db->order_by('airport_code', "asc");
        $query = $this->db->get('airports');
    foreach ($query->result_array() as $row){
        $data{$row['airport_code']} = $row['status'];
    }

    }return $data;
    }
    function create_member()
    {
        $new_member_insert_data = array('first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name'), 
            'email_address'=> $this->input->post('email_address'),
            'username'=> $this->input->post('username'),
            'password'=> md5($this->input->post('password'))
            'birthdate'=> $this->input->post('birthdate'),
            'base'=> $this->input->post('base')
        );
        $insert = $this->db->insert('membership', $new_member_insert_data);
        return $insert;
    }

} ?>

看法

echo form_dropdown('base', set_value('base', 'Select a Base'));

控制器

$this->form_validation->set_rules('base', 'Base', 'trim|required');
4

1 回答 1

0

一种方法是使您的下拉列表如下所示:

<?PHP 
                $options    =   $this->db->query('Select province_id as value, province as display FROM ndi_provinces')->result();
                $prov_options = array(''=>'Select');
                foreach($options as $option){
                    $prov_options[$option->value] = $option->display;
                }
                $prov_optionAtt = "id='province_id'  readonly='readonly'";
                echo form_dropdown('province_id',$prov_options, isset($_POST['province_id'])?$_POST['province_id']:$participant->province_id, $prov_optionAtt);
            ?><span class="required">*</span>

另一种更好的方法是在控制器中制作下拉选项并将其作为变量发送以查看

于 2013-06-15T05:41:12.217 回答