I'm inserting values from one table to another through html form using php, but the problem is the other table is having some extra fields say my tables are
我正在使用php通过html表单将值从一个表插入另一个表,但问题是另一个表有一些额外的字段说我的表是
table1(name, email, password, address, phno)
table1(姓名,电子邮件,密码,地址,phno)
and
table2(t_name, t_email, t_password, t_mobno, t_gender)
table2(t_name,t_email,t_password,t_mobno,t_gender)
how to insert the t_mobno
and t_gender
through form same time as i'm entering the other values.
如何在输入其他值的同时插入t_mobno和t_gender。
1 个解决方案
#1
1
Refer this:INSERT INTO SELECT
请参阅:INSERT INTO SELECT
This Is How I Did it, might help :
这就是我做到的,可能有所帮助:
$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
}
Here I have defined array_from_post in my base model you may use it like this:
在这里我已经在我的基础模型中定义了array_from_post,您可以像这样使用它:
public function array_from_post($fields){
$data = array();
foreach ($fields as $field) {
$data[$field] = $this->input->post($field);
}
return $data;
}
#1
1
Refer this:INSERT INTO SELECT
请参阅:INSERT INTO SELECT
This Is How I Did it, might help :
这就是我做到的,可能有所帮助:
$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
}
Here I have defined array_from_post in my base model you may use it like this:
在这里我已经在我的基础模型中定义了array_from_post,您可以像这样使用它:
public function array_from_post($fields){
$data = array();
foreach ($fields as $field) {
$data[$field] = $this->input->post($field);
}
return $data;
}