从多选下拉列表中获取数据并使用codeigniter php更新数据。无法从多选下拉列表中获取数据。在添加数据时,它正在成功插入。但是当我尝试获取要编辑的数据时,无法获取多选下拉列表。
控制器:
export GYP_DEFINES="OS=android"
gn gen out/Default --args='target_os="android" target_cpu="arm"'
型号:
function edit()
{
$data['categorylist']=$this->blogs_model->categories_dropdown();
$data['records']= $this->blogs_model->getblogsdata($this->uri->segment(3));
$data['mainpage']='blogs';
$data['mode']='edit';
$this->load->view('templates/template',$data);
}
function editblogs()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="message error"> ','</span>');
$this->form_validation->set_rules('category_id','Category Name','required');
$this->form_validation->set_rules('blog_title','Blog Title');
if($this->form_validation->run()== FALSE)
{
$data['categorylist']=$this->blogs_model->categories_dropdown();
$data['records']=$this->blogs_model->getblogsdata($this->input->post('blog_id'));
$data['mainpage']='blogs';
$data['mode']='edit';
$this->load->view('templates/template',$data);
}
else
{
$result = $this->blogs_model->update($this->input->post('blog_id'));
if(is_array($result))
{
$data['errors']=$result;
$data['records']=$this->blogs_model->getblogsdata($this->uri->segment('blog_id'));
$data['mainpage']='blogs';
$data['mode']='edit';
$this->load->view('templates/template',$data);
}
else
$this->flash->success('<h2>Successfully Updated the record.<h2>');
redirect('blogs');
}
}
查看:
function getblogsdata($id)
{
$this->db->select('blogs.*,C.category_name');
$this->db->from('blogs');
$this->db->join('categories AS C','C.category_id=blogs.category_id','INNER');
$this->db->where(array('blogs.blog_id'=>$id));
$q=$this->db->get();
if($q->num_rows()>0)
{
return $q->result();
}
else
{
return false;
}
}
function update($id)
{
$data=array(
'blog_title'=>$this->input->post('blog_title')
);
$this->db->where(array('blog_id'=>$id));
$this->db->update('blogs', $data);
return true;
$options = $this->input->post('category_id');
foreach($options as $opt){
$data1=array(
'category_id'=>$opt
);
$this->db->where(array('blog_id'=>$id));
$this->db->update('blog_categories',$data1);
}
}