Codeigniter 从另一个 table 插入数据并添加到输入 post
Codeigniter insert data from another table and add to input post
我有一个 table,其中包含 1 行包含产品费率的记录。
第二个 table,我的订单有姓名、电子邮件、联系电话、费用。
我想做的是,当客户为订单保存价值时,ratestb 的费率将节省成本。
这是我当前的模型,它只添加到 orderstb:
public function add($data)
{
$this->db->insert('orders', $data);
}
这是我的控制器:
public function addOrder()
{
$this->Order_model->add($this->input->post(null, true));
}
我的观点是字段名称、电子邮件和电话号码。
提前致谢!
您可以使用 $this->db->insert_id();
获取最后插入的数据
$this->db->insert('orders', $data);
$insert_id = $this->db->insert_id();
这将 return 成为您 table“订单”的主键。您现在可以通过执行get查询来获取数据。
$this->db->where('order_id', $insert_id);
$query = $this->db->get('orders');
我有一个 table,其中包含 1 行包含产品费率的记录。 第二个 table,我的订单有姓名、电子邮件、联系电话、费用。
我想做的是,当客户为订单保存价值时,ratestb 的费率将节省成本。
这是我当前的模型,它只添加到 orderstb:
public function add($data)
{
$this->db->insert('orders', $data);
}
这是我的控制器:
public function addOrder()
{
$this->Order_model->add($this->input->post(null, true));
}
我的观点是字段名称、电子邮件和电话号码。
提前致谢!
您可以使用 $this->db->insert_id();
获取最后插入的数据$this->db->insert('orders', $data);
$insert_id = $this->db->insert_id();
这将 return 成为您 table“订单”的主键。您现在可以通过执行get查询来获取数据。
$this->db->where('order_id', $insert_id);
$query = $this->db->get('orders');