如何在CodeIgniter中自动完成选择选项

时间:2019-06-27 07:55:55

标签: codeigniter autocomplete

我正在尝试在CodeIgniter中选择一个选项,并希望使其自动完成填充。我该怎么办?

这是我的代码:

型号:

public function get_nama_customer(){
        $data = array();
        $query = $this->db->get('tabel_customer');
        if($query->num_rows() > 0){
            foreach($query->result_array() as $row){
                $data[] = $row;

            }
        }

        $query->free_result();
        return $data;
    }

控制器:

public function add_data()
    {
        $this->load->model('model_tabel_material');
        $data['tabel_customer'] = $this->model_tabel_material->get_nama_customer();
        $this->load->view('datamaster/tabel_material/v_add_material', $data);
    }

public function do_add()
    {
        $nama_customer  = $_POST['nama_customer'];

        $data_add = array(
            "nama_customer"     => $nama_customer,
        );

        $temp = $this->model_tabel_material->insert_data('tabel_material', $data_add);
        if($temp >=1){
            redirect('tabel_material/controller_tabel_material/index');
        }
    }

查看:

<select class="form-control" name="nama_customer" id="nama_customer" required>
                                                <?php if(count($tabel_customer)){ ?>
                                                    <option value=''>--Pilih Customer--</option>
                                                    <?php foreach ($tabel_customer as $list){ ?>
                                                        <?php
                                                            echo "<option value='".$list['nama_customer']."'>".$list['nama_customer']."</option>";
                                                        ?>
                                                    <?php } ?>
                                                <?php } ?>
                                            </select>

0 个答案:

没有答案