gpt4 book ai didi

php - 如何在编辑 form_dropdown codeigniter 中显示所选项目

转载 作者:行者123 更新时间:2023-11-29 07:42:49 25 4
gpt4 key购买 nike

我在更新/编辑菜单时无法显示所选项目

该项目未被选择。如何让它自动选择?

这是我的模型

    public function master_kategorilapor(){
$this->db->order_by('id_kategorilapor');
$sql_kategorilapor=$this->db->get('kategorilapor');
if($sql_kategorilapor->num_rows()>0){
return $sql_kategorilapor->result_array();
}
}

这是 Controller

    public function tambah_lapor(){
$data['kategorilapor'] = $this->mymodel->master_kategorilapor();
$dd_kategorilapor = array();
foreach ($this->mymodel->master_kategorilapor() as $data_kategorilapor)
{
$dd_kategorilapor[$data_kategorilapor['id_kategorilapor']] = $data_kategorilapor['nama_kategorilapor'];
}
$data['kategorilapor']=$dd_kategorilapor;

$this->load->view ('petugas/tambah_lapor', $data);
}

Controller 获取更新数据

public function update_data ($id_lapor){


$this->load->model("mymodel");
$mhs = $this -> mymodel -> GetLapor("where id_lapor = '$id_lapor' ");
$data = array(
"id_lapor" => $mhs[0]['id_lapor'],
"tgl_lapor" => $mhs[0]['tgl_lapor'],
"t1" => $mhs[0]['t1'],
"t2" => $mhs[0]['t2'],
"dari" => $mhs[0]['dari'],
"untuk" => $mhs[0]['untuk'],
"id_tujuanlapor" => $mhs[0]['id_tujuanlapor'],
"id_kategorilapor" => $mhs[0]['id_kategorilapor'],
"isi_taruna" => $mhs[0]['isi_taruna'],
"keterangan_taruna" => $mhs[0]['keterangan_taruna']);


$this->load->view('petugas/update_lapor',$data);

}

这是我的观点

     <?php echo form_dropdown("id_kategorilapor",$kategorilapor); ?>

最佳答案

让我们看看下拉方法的基本形式。

$dd_list = array(
'Mr' => 'Mr',
'Mrs' => 'Mrs',
'Miss' => 'Miss',
);
echo form_dropdown('title', $dd_list, 'Mr');

这里我们创建了包含标题列表的数组。然后我们在表单中打印下拉列表。

假设我们要在数据库中存储 Mrs 的键值 1、Mrs 的键值 2、Miss 的键值 3,我们将上面的代码修改为:

 $dd_list = array(
'1' => 'Mr',
'2' => 'Mrs',
'3' => 'Miss',
);
echo form_dropdown('title', $dd_list, '3');

上面我们设置了 3:Miss 作为默认选择值。

让我们在上面的代码中添加 set_value 函数的基本形式。因此,表单会记住提交的内容,以防提交不完整。

$dd_list = array(
'1' => 'Mr',
'2' => 'Mrs',
'3' => 'Miss',
);

$dd_name = "title";

echo form_dropdown($dd_name, $dd_list, '3');

终于

 $dd_list = array(
'1' => 'Mr',
'2' => 'Mrs',
'3' => 'Miss',
);

$dd_name = "title";
$sl_val = $this->input->post($dd_name);

echo form_dropdown($dd_name, $dd_list, set_value($dd_name, ( ( !empty($sl_val) ) ? "$sl_val" : 3 ) ) );

关于php - 如何在编辑 form_dropdown codeigniter 中显示所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28576349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com