0

情况

我有一个用于在我的数据库中编辑公司的编辑表单。我使用连接表向公司添加类别。

我的桌子:

Companies
---------
idcompanies
companyname
country
telephone
etc...etc...

Categories
----------
idcategories
category

companycategories
-----------------
idcompanycategories
idcategories
idcompanies

问题

我的表单没有更新下拉列表。可能是什么问题呢?

我的下拉表单代码:

<?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>

我的更新控制器:

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");
}   

注意:当我将 'Category' => $this->input->post('categories') 添加到数据数组时,我得到错误未知列。

我的模型:

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; 
}

编辑:我发现它与我的 $selectie (选定值)有关。当我删除它时它有效。

4

2 回答 2

0

You need to set the multiselect values of the dropdown instead of key() use set_multiselect('categorieen',$selectie) )

Try this

 <td><?= form_dropdown('categorieen', $opties, set_multiselect('categorieen',$selectie)); ?></td>

For reference see this Hope it helps

于 2013-05-30T08:06:15.797 回答
0

事实证明,以下代码行是问题所在:

if($this->db->affected_rows() >= 1) 
{ 
$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');

$this->insert_bedrijfcat1($to_bedrijfcategorieen2); 
}else{ 
return FALSE;
} 

它一定要是:

$to_bedrijfcategorieen2['idcategorieen'] = $this->input->post('categorieen');

$this->insert_bedrijfcat1($to_bedrijfcategorieen2); 

我真的不知道为什么这给了我这个问题。但是通过删除它修复了它。

于 2013-05-30T08:21:41.197 回答