Situation
I have an editform for editing companies in my database. I use a joined table to add a category to the company.
我有一个editform用于编辑我的数据库中的公司。我使用连接表为公司添加类别。
My tables:
Companies
---------
idcompanies
companyname
country
telephone
etc...etc...
Categories
----------
idcategories
category
companycategories
-----------------
idcompanycategories
idcategories
idcompanies
Question
My form is not updating the dropdown. what could be the problem?
我的表单没有更新下拉列表。可能是什么问题呢?
My dropdown form code:
我的下拉表单代码:
<?php
foreach($selected as $row){
$selectie[$row->idcategorieen] = $row->Categorie;
}
?>
<tr>
<td><?= form_label('Categorieen'); ?></td>
<td><?= form_dropdown('categorieen', $opties, key($selectie)); ?></td>
</tr>
My controller for updating:
我的控制器更新:
function updatebedrijven()
{
$dbres = $this->db->get('categorieen');
$ddmenu = array();
foreach ($dbres->result_array() as $tablerow) {
$ddmenu[$tablerow['idcategorieen']] = $tablerow['Categorie'];
}
$data['opties'] = $ddmenu;
$id = $this->uri->segment(3);
$id2 = $this->uri->segment(3);
$data['selected'] = $this->members_model->getselection($id2);
$data['info'] = $this->members_model->getbedrijf($id);
$data['id'] = $id;
$this->load->view('members/header');
$this->load->view('members/editform', $data);
$this->load->view('members/footer');
}
function update()
{
$id = $this->uri->segment(3);
echo 'id: '.$id;
$data = array(
'Bedrijfsnaam' => $this->input->post('Bedrijfsnaam'),
'Postcode' => $this->input->post('Postcode'),
'Plaats' => $this->input->post('Plaats'),
'Telefoonnummer' => $this->input->post('Telefoonnummer'),
'Email' => $this->input->post('Email'),
'Website' => $this->input->post('Website'),
'Profiel' => $this->input->post('Profiel'),
'Adres' => $this->input->post('Adres'),
);
if($this->input->post('logo')) { $data['logo'] = $this->input->post('logo'); }
$this->members_model->updatebedrijf($id, $data);
$b = $this->session->userdata('idbedrijven');
redirect("members/$b");
}
NOTE: when i add 'Category' => $this->input->post('categories') to the data array I get the error unknown column.
注意:当我将'Category'=> $ this-> input-> post('categories')添加到数据数组时,我得到错误未知列。
My model:
function updatebedrijf($id, $data)
{
$this->db->where('idbedrijven', $id);
$this->db->update('bedrijven', $data);
if($this->db->affected_rows() >= 1)
{
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
}else{
return FALSE;
}
}
function insert_bedrijfcat1($data1)
{
$id = $this->uri->segment(3);
$this->db->where('idbedrijven', $id);
$this->db->update('bedrijfcategorieen', $data1);
return $this->db->affected_rows() >= 1 ? TRUE : FALSE;
}
EDIT: I figured out it has something to do with my $selectie (selected value). when I delete that it works.
编辑:我发现它与我的$ selectie(选定值)有关。当我删除它的工作原理。
2 个解决方案
#1
0
You need to set the multiselect
values of the dropdown instead of key()
use set_multiselect('categorieen',$selectie) )
您需要设置下拉菜单的多选值而不是key()使用set_multiselect('categorieen',$ selectie))
Try this
<td><?= form_dropdown('categorieen', $opties, set_multiselect('categorieen',$selectie)); ?></td>
For reference see this Hope it helps
如需参考,希望它有所帮助
#2
0
It turned out that the following line of code was the problem:
事实证明,以下代码行是问题所在:
if($this->db->affected_rows() >= 1)
{
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
}else{
return FALSE;
}
It has to be:
它一定要是:
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
I don't really know why this gave me the problem. But it was fixed by deleting it.
我真的不知道为什么这给了我这个问题。但它通过删除它来解决。
#1
0
You need to set the multiselect
values of the dropdown instead of key()
use set_multiselect('categorieen',$selectie) )
您需要设置下拉菜单的多选值而不是key()使用set_multiselect('categorieen',$ selectie))
Try this
<td><?= form_dropdown('categorieen', $opties, set_multiselect('categorieen',$selectie)); ?></td>
For reference see this Hope it helps
如需参考,希望它有所帮助
#2
0
It turned out that the following line of code was the problem:
事实证明,以下代码行是问题所在:
if($this->db->affected_rows() >= 1)
{
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
}else{
return FALSE;
}
It has to be:
它一定要是:
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');
$this->insert_bedrijfcat1($to_bedrijfcategorieen2);
I don't really know why this gave me the problem. But it was fixed by deleting it.
我真的不知道为什么这给了我这个问题。但它通过删除它来解决。