Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/480.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从单一表单提交将数据插入多个表_Javascript_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Javascript 从单一表单提交将数据插入多个表

Javascript 从单一表单提交将数据插入多个表,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,我有下面提到的表格 并获得以下输出 使用foreach循环帮助我获得如下输出 array('notification') = array('pos_id' => 'kiran','post_usr' => 'kumar','comment' => 'kaleti'); array('project') = array('Project_name' => 'india','Proejct_lang' => 'hyderabad'); 这是控制器代码 // contr

我有下面提到的表格

并获得以下输出

使用foreach循环帮助我获得如下输出

array('notification') = array('pos_id' => 'kiran','post_usr' => 'kumar','comment' => 'kaleti');
array('project') = array('Project_name' => 'india','Proejct_lang' => 'hyderabad');
这是控制器代码

// controller
public function form_submit() { 
  $total_data = $this->input->post(); 
  print_r($total_data);
  //output :Array ( [notification|pos_id] => kiran [notification|post_usr] => kumar [notification|comment] => kaleti [project|Project_name] => india [project|Proejct_lang] => hyderabad )
  foreach ( $total_data as $key => $value ) { 
    $arr = explode("|",$key); 
    echo $arr[0]."--".$arr[1]."--".$value."<br />"; 
  }
}
//控制器
公共函数表单_submit(){
$total_data=$this->input->post();
打印(总数据);
//输出:数组([notification | pos|u id]=>kiran[notification | post|u usr]=>kumar[notification | comment]=>kaleti[project | project | u name]=>india[project | Proejct_lang]=>海德拉巴)
foreach($key=>$value的总数据){
$arr=分解(“|”,$key);
echo$arr[0]。“-”$arr[1]。“-”$value.“
”; } }
这是控制器代码,您将从
视图中获取数据,作为输入视图字段,您将在
控制器中收集这些数据

// Controller
$data_array1 = array(
    'table_field_name_here' => $this->input->post('pos_id'),
    'table_field_name_here' => $this->input->post('post_usr'),
    'table_field_name_here' => $this->input->post('comment'),
);

$data_array2 = array(
    'table_field_name_here' => $this->input->post('Project_name'),
    'table_field_name_here' => $this->input->post('Proejct_lang'),
);  

$table_1 = 'table_name';
$table_2 = 'table_name';
$record_id_1 = $this->Common_model->insert_into_table($table_1, $data_array1);
$record_id_2 = $this->Common_model->insert_into_table($table_2, $data_array2);
if($record_id_1 && $record_id_2){
    // success ...!
}else{
    // fail ...!    
}
将从控制器调用的
模型
函数

// Model
function insert_into_table($table, $data) {
    // echo "<pre>asdf";print_r($data);exit;
    $insert = $this->db->insert($table, $data);
    $insert_id = $this->db->insert_id();
    if ($insert) {
        return $insert_id;
    } else {
        return false;
    }
}
//模型
函数将_插入_表($table,$data){
//回显“asdf”;打印($data);退出;
$insert=$this->db->insert($table,$data);
$insert_id=$this->db->insert_id();
如果($插入){
返回$insert_id;
}否则{
返回false;
}
}

希望您能了解使用模型将数据插入两个表是多么简单。

根据数组,您可以将数据插入一个表中,现在的问题在哪里?您现在编写了什么代码。@M.Hemant先生,请检查controller.public function form_submit(){$total_data=$this->input->post();foreach中的以下代码($total_data as$key=>$value){$arr=explode(“|”,$key);echo$arr[0]。“--”$arr[1]。“--”$value.
“;}}}@NomanJaved先生,如何将所提到的输出转换为数组格式。请参见我的控制器函数:::公共函数form_submit(){$total_data=$this->input->post();foreach($total_data as$key=>$value){$arr=explode(“|“,$key”);echo$arr[0]。“--$arr[1]。”--“$value”。
“;}}}。首先检查值。在foreach循环中添加
echo”“;打印($value);退出;
,并检查返回的数据。