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

次のコード行が問題であることが判明しました。

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 に答える
0

使用するmultiselect代わりに、ドロップダウンの値を設定する必要がありますkey()set_multiselect('categorieen',$selectie) )

これを試して

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

参考までに、これを参照してください。

于 2013-05-30T08:06:15.797 に答える