gpt4 book ai didi

php - 通过表单将数据从一个表插入到另一个表

转载 作者:可可西里 更新时间:2023-11-01 07:38:55 25 4
gpt4 key购买 nike

我正在使用 php 通过 html 表单将值从一个表插入到另一个表,但问题是另一个表有一些额外的字段说我的表是

table1(name, email, password, address, phno)

table2(t_name, t_email, t_password, t_mobno, t_gender)

如何在我输入其他值的同时通过表单插入 t_mobnot_gender

最佳答案

引用这个:INSERT INTO SELECT

我是这样做的,可能会有帮助:

$query = $this->db->get('Table1')->result(); // get first table
foreach($query as $result)
{
//Your Post Values from form data in array : POST_DATA
$post_data = array_from_post('filed1,filed2....');

$data = array_merge($result,$post_data);

$this->db->insert('Table2', $data); // insert each row to another table
}

这里我在我的基本模型中定义了 array_from_post 你可以像这样使用它:

public function array_from_post($fields){
$data = array();
foreach ($fields as $field) {
$data[$field] = $this->input->post($field);
}
return $data;
}

关于php - 通过表单将数据从一个表插入到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36077650/

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