Codeigniter:“字段列表”中的未知列“ Array”

时间:2019-08-03 07:00:10

标签: arrays codeigniter

嗨,我想在一个单独的表中添加一个数组值,一个提交中有2个表。已插入办公室详细信息,但在教育详细信息中可能会出现一些错误。

我的控制器代码如下:

  public function insertofficedt()
{   
    $empid = $this->session->userdata('last_id');   
    $join_date=$_POST['join_date'];
    $pan_no=$_POST['pan_no'];
    $emp_department=$_POST['emp_department'];
    $emp_designation=$_POST['emp_designation'];
    $emp_jobstatus=$_POST['emp_jobstatus'];
    $joining_salary=$_POST['joining_salary'];

    $data=array(
            'emp_id'=>$empid,
            'join_date'=>$join_date,
            'pan_no'=>$pan_no,
            'emp_department'=>$emp_department, 
            'emp_designation'=>$emp_designation, 
            'emp_jobstatus'=>$emp_jobstatus, 
            'joining_salary'=>$joining_salary,
            'joinon'=>date('d-m-Y')
        ); 
    $this->db->insert('emp_officedt',$data); 

    $r = isset($_POST['college_name']) ? sizeof($_POST['college_name']) : 0;
    for ($i = 0; $i < $r; $i++) {
        //$empid = $this->session->userdata('last_id');  
        $college_name = $_POST['college_name'][$i];
        $college_location = $_POST['college_location'][$i];
        $degree = $_POST['degree'][$i];
        $year_passout = $_POST['year_passout'][$i]; 
        if (!empty($college_name) && !empty($college_location)) {
            $college[] = array(
                'emp_id' => $empid,
                'college_name' => $college_name,
                'college_location' => $college_location,
                'degree' => $degree,
                'year_passout' => $year_passout 
            );
            //print_r($college);exit();
        }
    }
        $insert = count($college);
    if($insert)
    {
        $this->db->insert('emp_edudt', $college);
    } 
    return $insert;
    redirect('employee/addbankdt', 'refresh');     
}

我的观看代码如下:

<div class="form-group row">
    <div class="col-sm-6"> 
        <label>Date Of Joining</label> 
        <input type="date" name="join_date" class=" form-control" placeholder="Date Of Joining">
    </div> 
    <div class="col-sm-6">
        <label>Pan No</label> 
        <input type="text" name="pan_no" class=" form-control" placeholder="Pan No">
    </div> 
</div>
<div class="form-group row">
    <div class="col-sm-6">
        <label>Department</label> 
        <select name="emp_department" class=" form-control">  
        <option value="">Select Department</option>
            <?php foreach($departments as $process_packed_info){ ?>
            <option value="<?php echo $process_packed_info->department_id?>"><?php echo $process_packed_info->department_name; ?></option>
            <?php } ?> 
        </select>
    </div>
    <div class="col-sm-6">
        <label>Designation</label>  
        <select name="emp_designation" class="form-control"> 
            <option value="">Select Designation</option>
            <?php foreach($designation_new as $designation_info){ ?>
            <option value="<?php echo $designation_info->designation_id; ?>"><?php echo $designation_info->designation_name; ?> ?></option>
            <?php } ?>  
        </select>
    </div>
</div>
<div class="form-group row">
    <div class="col-sm-6">
        <label>Job Status</label>
        <select name="emp_jobstatus" class=" form-control">
            <option value="">Select Job Status</option>
            <option value="permanent">Permanent</option>
            <option value="temporary">Temporary</option> 
        </select>
    </div> 
    <div class="col-sm-6">
        <label>Joining Salary</label> 
        <input type="text" name="joining_salary" class=" form-control" placeholder="Joining Salary">
    </div> 
</div>  

<hr color="#0073aa"> 
<h5>Educational Details</h5><br><br>
<div class="form-group row">  
    <div class="col-md-6">
        <table class="table table-striped table-hover">
            <tr>
                <th>College Name</th>
                <th>Location</th>
                <th>Degree</th>
                <th>Year of Passout</th>
            </tr>
            <tr>
                <td> 
                    <div class="form-group">                    
                        <div class="controls"><?= form_input('college_name[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div>
                    </div>        
                </td>
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('college_location[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('degree[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                           
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('year_passout[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                             
            </tr>
            <tr>
                <td> 
                    <div class="form-group">                    
                        <div class="controls"><?= form_input('college_name[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div>
                    </div>        
                </td>
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('college_location[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('degree[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                           
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('year_passout[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                             
            </tr> 
            <tr>
                <td> 
                    <div class="form-group">                    
                        <div class="controls"><?= form_input('college_name[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div>
                    </div>        
                </td>
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('college_location[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('degree[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                           
                <td> 
                    <div class="form-group">                 
                        <div class="controls"><?= form_input('year_passout[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                             
            </tr> 
        </table>
    </div>
    <div class="col-md-6">
        <table class="table table-striped table-hover">
            <tr>
                <th class="text-center">School Name</th>
                <th class="text-center">Location</th>
                <th class="text-center">Standard</th>
                <th class="text-center">Year of Passout</th>
            </tr>
            <tr>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('school_name[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div>
                    </div>        
                </td>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('school_location[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('standard[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                           
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('passout[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                             
            </tr>
            <tr>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('school_name[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div>
                    </div>        
                </td>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('school_location[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('standard[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                           
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('passout[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                             
            </tr>
            <tr>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('school_name[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div>
                    </div>        
                </td>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('school_location[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('standard[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                           
                <td> 
                    <div class="form-group"> 
                        <div class="controls"><?= form_input('passout[]', '', 'class="form-control" style="padding: 5px 13px;"');?>
                        </div> 
                    </div> 
                </td>                             
            </tr>
        </table>
    </div>
</div>

我想以数组格式存储记录。请帮助我解决问题。我是Codeigniter的新手。

1 个答案:

答案 0 :(得分:1)

尝试一下, 控制器代码:

HttpClient

型号代码:

public function insertofficedt(){
   $this->load->model('User_model');
    $result = $this->User_model->batchinsert($_POST);
    }

该表的查看代码应为:

   public function batchinsert($data){
     $empid = $this->session->userdata('last_id');   
        $join_date=$_POST['join_date'];
        $pan_no=$_POST['pan_no'];
        $emp_department=$_POST['emp_department'];
        $emp_designation=$_POST['emp_designation'];
        $emp_jobstatus=$_POST['emp_jobstatus'];
        $joining_salary=$_POST['joining_salary'];

        $da=array(
                'emp_id'=>$empid,
                'join_date'=>$join_date,
                'pan_no'=>$pan_no,
                'emp_department'=>$emp_department, 
                'emp_designation'=>$emp_designation, 
                'emp_jobstatus'=>$emp_jobstatus, 
                'joining_salary'=>$joining_salary,
                'joinon'=>date('d-m-Y')
            ); 
        $this->db->insert('emp_officedt',$da); 

    $count = count($data['college_name']);
    for($i = 0; $i<$count; $i++){ 
    $college[] = array(
     'emp_id' => $empid,
                    'college_name' => $data['college_name'][$i],
                    'college_location' =>$data['college_location'][$i],
                    'degree' => $data['degree'][$i],
                    'year_passout' => $data['year_passout'][$i],
                );
    }
     $this->db->insert_batch('emp_edudt', $college);
}