php - How to add records to database using a joined table - codeigniter -
i made form adding factories database. works great can't show factories on page because they're in joined table, when submit page not add id joined table factory won't shown @ page.
the joined table looks this:
bedrijfcategorieen ------------------ idbedrijfcat idbedrijven idcategorieen where idbedrijven id factories table.
my controller function adding factories:
function bedrijven() { $data['options'] = $ddmenu; $this->load->view('members/header'); $this->load->view('members/editform', $data); $this->load->view('members/footer'); } function addbedrijven() { $this->members_model->addbedrijf(); redirect('members/index'); } my model function adding factories:
function addbedrijf() { $data = array( 'idbedrijven' => $idbedrijven, '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'), 'logo' => $this->input->post('logo') ); $this->db->insert('bedrijven', $data); } i add factories trough joined table. easier add categories factories too.
i tried where('bedrijfcategorieen.idbedrijven = idbedrijven did not work.
table scheme
factories --------- idfactories factoryname adress postcode country telephone ... ... categories ---------- idcategories category factorycategories ----------------- idfactorycat idfactories idcategories
if understand right - want add records 2 different tables via join. not possible. you'll have 2 write separate insert statements both tables.
take @ active record's documentation http://ellislab.com/codeigniter/user-guide/database/helpers.html , read $this->db->insert_id(); may give clues how write insert statement.
Comments
Post a Comment