gpt4 book ai didi

php - 如何将父ID输入到不同表的数据库中

转载 作者:搜寻专家 更新时间:2023-10-30 20:49:28 26 4
gpt4 key购买 nike

我有表 -> 子类别

subkategori

而且我无法将 id_kategori 属性插入到表组合中

portofolio

我有模型的代码:

function get_subcategories($id_kategori){

$query = $this->db->query("SELECT id_kategori from subkategori WHERE id_subkategori=".$this->input->post('a'));
return $query->result();
}

Controller 在这里:

if ($this->input->post('a')!=''){
$this->load->model('Model_app');
$this->model_app->get_subcatoegories('$id_kategori');
}else{
$id_kategori = '';
}
$data = array(
'id_subkategori'=>$this->db->escape_str($this->input->post('a')),
'id_kategori'=>$id_kategori
);

最佳答案

$this->input->post('a') as you mentioned here I assume that you have input in the form and its name is a.

在 Controller 中

if (!empty($this->input->post('a')))
{
$this->load->model('Model_app');
$id = $this->model_app->get_subcatoegories($this->input->post('a'));

if (empty($id)) {
$id_kategori = '';
} else {
$id_kategori = $id[0]['id_kategori'];
}

}else{
$id_kategori = '';
}

$data = array(
'id_subkategori'=>$this->db->escape_str($this->input->post('a')),
'id_kategori'=>$id_kategori
);

在模型中

function get_subcategories($id_kategori)
{
$query = $this->db->query("SELECT id_kategori FROM subkategori WHERE id_subkategori = $id_kategori");
return $query->result_array();
}

如果使用 $this->db->insert_id();

你可以最后插入

关于php - 如何将父ID输入到不同表的数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47343506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com