I made a form for adding factories to my database. this works great but i can't show my factories on the page because they're in a joined table, but when i submit the page it does not add an id to the joined table so the factory won't be shown at the page.
我制作了一个表格,用于将工厂添加到我的数据库这很好但我不能在页面上显示我的工厂,因为它们在一个连接表中,但是当我提交页面时,它不会在连接表中添加id,因此工厂将不会显示在页面上。
the joined table looks like this:
连接表看起来像这样:
bedrijfcategorieen
------------------
idbedrijfcat
idbedrijven
idcategorieen
Where idbedrijven is the id for my factories table.
idbedrijven是我工厂表的id。
My controller function for 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 for 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 would like to add my factories trough the joined table. so it would be easier to add categories to the factories too.
我想通过连接表添加我的工厂。因此,向工厂添加类别也会更容易。
I tried where('bedrijfcategorieen.idbedrijven = idbedrijven
but it did not work.
我尝试过哪里('bedrijfcategorieen.idbedrijven = idbedrijven但它没有用。
table scheme
表格方案
factories
---------
idfactories
factoryname
adress
postcode
country
telephone
...
...
categories
----------
idcategories
category
factorycategories
-----------------
idfactorycat
idfactories
idcategories
1 个解决方案
#1
0
If I understand you right - you want to add records to two different tables via JOIN. This is not possible. You'll have two write separate insert statements for both the tables.
如果我理解你 - 你想通过JOIN将记录添加到两个不同的表。这不可能。您将为这两个表分别编写两个插入语句。
Take a look at the Active Record's documentation http://ellislab.com/codeigniter/user-guide/database/helpers.html and read about $this->db->insert_id();
This may give you clues about how to write your insert statement.
查看Active Record的文档http://ellislab.com/codeigniter/user-guide/database/helpers.html并阅读有关$ this-> db-> insert_id()的信息。这可能会为您提供有关如何编写insert语句的线索。
#1
0
If I understand you right - you want to add records to two different tables via JOIN. This is not possible. You'll have two write separate insert statements for both the tables.
如果我理解你 - 你想通过JOIN将记录添加到两个不同的表。这不可能。您将为这两个表分别编写两个插入语句。
Take a look at the Active Record's documentation http://ellislab.com/codeigniter/user-guide/database/helpers.html and read about $this->db->insert_id();
This may give you clues about how to write your insert statement.
查看Active Record的文档http://ellislab.com/codeigniter/user-guide/database/helpers.html并阅读有关$ this-> db-> insert_id()的信息。这可能会为您提供有关如何编写insert语句的线索。