Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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
Php 如何在单次提交中逐行插入值_Php_Codeigniter - Fatal编程技术网

Php 如何在单次提交中逐行插入值

Php 如何在单次提交中逐行插入值,php,codeigniter,Php,Codeigniter,这是我的查看页面 这是动态字段测试名称和单位是从表我需要插入测试名称和结果和正常值也单位 我的控制器 $patient_id = $this->input->post('patient_id'); $doctor_id = $this->input->post('doctor_id'); $prescription_id = $this->input->post

这是我的查看页面

这是动态字段测试名称和单位是从表我需要插入测试名称和结果和正常值也单位

我的控制器

 $patient_id = $this->input->post('patient_id');
                        $doctor_id = $this->input->post('doctor_id');
                        $prescription_id = $this->input->post('prescription_id'); 
                        $lab_result =$this->input->post('lab_result');
                        $lab_test =$this->input->post('lab_test');
                        $units =$this->input->post('units');
                       $normal_value =$this->input->post('normal_value');
                       $cat_id = $this->input->post('cat_id');

     for($i=0; $i<count($prescription_id); $i++)
           {
                    $labreport[] = array(
                       'patient_id' => $patient_id[$i],
                       'doctor_id' => $doctor_id[$i],
                       'prescription_id' =>$prescription_id[$i],
                       'lab_result'   => $lab_result[$i],
                       'lab_test'     => $lab_test[$i],
                       'units'        =>  $units[$i],
                       'normal_value' => $normal_value[$i],
                       'cat_id' => $cat_id, );
                      //echo '<pre>'; print_r($labreport); '</pre>'; exit; 
                         }
                       $stringlabreport= json_encode($labreport);
                         $this->db->insert('patient_lab_report',$stringlabreport); 
                          if($this->db->affected_rows()){
                        return true;
                    } else {
                        return false;
                    }
        $this->session->set_flashdata('message','Lab Report  Added Successfully');
                          redirect('laboratory_report/all');

 =========================
$patient_id=$this->input->post('patient_id');
$doctor\u id=$this->input->post('doctor\u id');
$prescription\u id=$this->input->post('prescription\u id');
$lab_result=$this->input->post('lab_result');
$lab_test=$this->input->post('lab_test');
$units=$this->input->post('units');
$normal_value=$this->input->post('normal_value');
$cat_id=$this->input->post('cat_id');
对于($i=0;$i$患者id[$i],
“医生id”=>$doctor\u id[$i],
“处方id”=>$PRECUMENT\U id[$i],
“实验室结果”=>$lab_结果[$i],
“实验室测试”=>实验室测试[$i],
“单位”=>$units[$i],
“正常值”=>$normal\u值[$i],
“cat_id”=>$cat_id,);
//回声';打印($labreport);“”;出口
 <tr>   
                            <td><input type="hidden" value="<?php echo $data->name; ?>"name="lab_test[]"><?php echo $data->name; ?></td>                        
                            <td><input type="text" value=""        name="lab_result[]" class="form-control"></td>
                            <td><input type="hidden" value="<?php echo $data->units; ?>"    name="units[] "> <?php echo $data->units; ?></td>
                            <td><input type="hidden" value="<?php echo $data->n_value; ?>" name="normal_value[] "> <?php echo $data->n_value; ?></td>
                        </tr>
} $stringlabreport=json_encode($labreport); $this->db->insert('patient\u lab\u report',$stringlabreport); 如果($this->db->infected_rows()){ 返回true; }否则{ 返回false; } $this->session->set_flashdata('message','Lab Report Added Successfully'); 重定向(“实验室报告/全部”); =========================
这是我的视图代码

<form action="" method="post" name="someform">
    <input name="row[0][test_name]"/>
    <input name="row[0][result]"/>
    <input name="row[1][test_name]"/>
    <input name="row[1][result]"/>
    <input type="submit" name="submitted" value="send">
</form>


使用数组名称进行输入。即:

<?php

$submitted = filter_input(INPUT_POST, 'submitted');
if(!empty($submitted)){

    $rows = filter_input(INPUT_POST,'row',  FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
    $parsed_rows = [];
    foreach($rows as $row){
        if(!empty($row['test_name']) && !empty($row['result'])){
            $parsed_rows[] = $row;
        }
    }

}

?>

您的控制器和型号在哪里?欢迎来到SO,分享您迄今为止的尝试。共享您的代码,以便我们可以帮助您。@kesavan您可以编辑问题并添加控制器代码和模型吗code@MasivuyeCokile Updated@kesavan请将此作为问题的一部分提供