Php 如何从post方法获取值并在foreach循环中分解

Php 如何从post方法获取值并在foreach循环中分解,php,codeigniter,loops,foreach,Php,Codeigniter,Loops,Foreach,如何从post方法中获取值并在foreach循环中分解 public function generate_all_payslip() { $data['title'] = "Generate All Payslip"; $this->payroll_model->_table_name = "tbl_department"; //table name $this->payroll_model->_order_by = "department_id"

如何从post方法中获取值并在foreach循环中分解

public function generate_all_payslip() {
    $data['title'] = "Generate All Payslip";
    $this->payroll_model->_table_name = "tbl_department"; //table name
    $this->payroll_model->_order_by = "department_id";
    $all_dept_info = $this->payroll_model->get();
    // get all department info and designation info
    $dataalldep = array();
    foreach ($all_dept_info as $v_dept_info) {
        $dataalldep['all_department_info'][] = $this->payroll_model->get_add_department_by_id($v_dept_info->department_id);
    }
    foreach ($dataalldep['all_department_info'] as $keyemp=>$valemparray) {
        $datae = array();
        foreach($valemparray as $k=>$v) {
            $datae['flag'] = 1;
            $datae['designations_id'] = $v->designations_id;
            $this->input->post('gapsbtn', TRUE);
            $dataee['payment_date'] = $this->input->post('payment_date', TRUE);
            $datepaymentmades = explode("-",$dataee['payment_date']);
            $currentyears = $datepaymentmades[0];
            $currentmonths = $datepaymentmades[1];
            $currentyear = $currentyears ;
            $currentmonth = $currentmonths ;
            $datae['payment_date'] = $currentyear."-".$currentmonth;
            $datae['employee_info'] = $this->payroll_model->get_emp_salary_list($emp = NULL, $datae['designations_id']);
            $basicwagessalaey = $datae['employee_info'][0]->basic_salary;
            $gross =  $datae['employee_info'][0]->house_rent_allowance + $datae['employee_info'][0]->medical_allowance + $datae['employee_info'][0]->special_allowance + $datae['employee_info'][0]->fuel_allowance + $datae['employee_info'][0]->phone_bill_allowance + $datae['employee_info'][0]->other_allowance;
            $deduction = $datae['employee_info'][0]->tax_deduction + $datae['employee_info'][0]->provident_fund + $datae['employee_info'][0]->other_deduction;
            $net_extra = $gross - $deduction;
            $workingdayscurrentmonth = $this->countDays($currentyear,$currentmonth, array(0));
            $perdaysaaryperuser = $basicwagessalaey/30;
            ### full day ###
            $queryfullday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='1' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
            $attendancecountarray = $queryfullday->result_array();
            $attendancecounting = $attendancecountarray[0]['present_days'];
            //$attendancecounting = 24;
            $data['attendancecounting'] = $attendancecountarray[0]['present_days'];
            if ($attendancecounting == $workingdayscurrentmonth) {
                $data['totalmonthwagesfullday'] = ($perdaysaaryperuser*30)+$perdaysaaryperuser;
            } else {
                if ($workingdayscurrentmonth == 27) {
                    $data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*3);
                }
                if ($workingdayscurrentmonth == 26) {
                    $data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*4);
                }
                if ($workingdayscurrentmonth == 25) {
                    $data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*5);
                }
                if ($workingdayscurrentmonth == 24) {
                    $data['totalmonthwagesfullday'] = ($perdaysaaryperuser*$attendancecounting)+($perdaysaaryperuser*6);
                }
            }
            ### half day ###
            $queryhalfday = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='2' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
            $attendancecountarray_half = $queryhalfday->result_array();
            $attendancecounting_half = $attendancecountarray_half[0]['present_days'];
            //$attendancecounting_half = 1;
            $data['attendancecounting_half'] = $attendancecountarray_half[0]['present_days'];
            $data['totalmonthwages_half'] = ($perdaysaaryperuser/2)*$attendancecounting_half;
            ### leave day ###
            $queryleave = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='3' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
            $attendancecountarray_leave = $queryleave->result_array();
            $attendancecounting_leave = $attendancecountarray_leave[0]['present_days'];
            //$attendancecounting_leave = 2;
            $data['attendancecounting_leave'] = $attendancecountarray_leave[0]['present_days'];
            $data['totalmonthwages_leave'] = $perdaysaaryperuser*$attendancecounting_leave;
            ### absent day ###
            $queryabsent = $this->db->query("SELECT count(attendance_id) AS present_days FROM `tbl_attendance` WHERE attendance_status='0' AND month(date) = $currentmonth and year(date) = $currentyear AND employee_id='".$data['employee_info'][0]->employee_id."'");
            $attendancecountarray_absent = $queryabsent->result_array();
            $attendancecounting_absent = $attendancecountarray_absent[0]['present_days'];
            //$attendancecounting_absent = 1;
            $data['attendancecounting_absent'] = $attendancecountarray_absent[0]['present_days'];
            $data['totalmonthwages_absent'] = $perdaysaaryperuser*$attendancecounting_absent;
            ######################
            $querylastsalary  = $this->db->query("SELECT * FROM `tbl_salary_payment` WHERE employee_id='".$data['employee_info'][0]->employee_id."' Order BY salary_payment_id desc LIMIT 1");
            $lastsalary = $querylastsalary->result_array();
            $paymentamountlastmonth = $lastsalary[0]['payment_amount'];
            $data['totalmonthwage'] = ($data['totalmonthwagesfullday']+$data['totalmonthwages_half']+$net_extra)-($data['totalmonthwages_absent']);
            if ($paymentamountlastmonth < 0) {
                $data['totalmonthwages'] = $data['totalmonthwage']+$paymentamountlastmonth;
            } else {
                $data['totalmonthwages'] = $data['totalmonthwage'];
            }
            ########## insert into tbl_salary_payment ##########
            if ($datae['employee_info'][0]->employee_id !="") {
                $dbinsert = array();
                $dbinsert['employee_id'] = $datae['employee_info'][0]->employee_id;
                $dbinsert['basic_salary'] = $datae['employee_info'][0]->basic_salary;
                $dbinsert['house_rent_allowance'] = $datae['employee_info'][0]->house_rent_allowance;
                $dbinsert['medical_allowance'] = $datae['employee_info'][0]->medical_allowance;
                $dbinsert['special_allowance'] = $datae['employee_info'][0]->special_allowance;
                $dbinsert['fuel_allowance'] = $datae['employee_info'][0]->fuel_allowance;
                $dbinsert['phone_bill_allowance'] = $datae['employee_info'][0]->phone_bill_allowance;
                $dbinsert['other_allowance'] = $datae['employee_info'][0]->other_allowance;
                $dbinsert['tax_deduction'] = $datae['employee_info'][0]->tax_deduction;    
                $dbinsert['provident_fund'] = $datae['employee_info'][0]->provident_fund;
                $dbinsert['other_deduction'] = $datae['employee_info'][0]->other_deduction;
                $dbinsert['payment_for_month'] = $datae['payment_date'];
                $dbinsert['payment_type'] = 'Cash Payment';
                $dbinsert['payment_date'] = date('Y-m-d H:i:s');
                $dbinsert['payment_amount'] = round($totalmonthwages);
                $dbinsert['present'] = $attendancecounting;
                $dbinsert['halfday'] = $attendancecounting_half;
                $dbinsert['leave'] = $attendancecounting_leave;
                $dbinsert['absent'] = $attendancecounting_absent;
                $insertedid = $this->payroll_model->insertpayrolldata($dbinsert);
                ####### insert into tbl_salary_payslip ###
                $dbinsertpayslip = array();
                $dbinsertpayslip['payslip_number'] = date('Ymd');
                $dbinsertpayslip['salary_payment_id'] = $insertedid;
                $this->payroll_model->insertpayslipdata($dbinsertpayslip);
            }
        }
    }    
    $data['subview'] = $this->load->view('admin/payroll/generate_all_payslip', $data, TRUE);
    $this->load->view('admin/_layout_main', $data);
}
如果我使用

$currentyear = date('Y');
    $currentmonth = date('m');
工作正常。但我想使用我选择的日期,而不是当前系统日期 如何更正此代码。目前我看到这个错误

此页面不工作

example.com当前无法处理此请求。
HTTP错误500


下面提到的行是否有任何具体的用途

$datepaymentmades = explode("-",$dataee['payment_date']);
或者你让我们知道你想用这个做什么

如果您想要月、日和年,请在下面检查

$paymentDate = strtotime($dataee['payment_date']);
$month = date("m",strtotime($paymentDate));
$year = date("Y",strtotime($paymentDate));
$day = date("d",strtotime($paymentDate));

建议我如何更正此代码如果您还没有,请添加
error\u reporting(E\u ALL);ini设置(“显示错误”,1)这应该能告诉你为什么会出错。如果我删除这个$This->input->post('gapsbtn',TRUE)$数据对象['payment\u date']=$this->input->post('payment\u date',TRUE)$datepaymentmades=爆炸(“-”,$dataee['payment_date'])$currentyears=$datepaymentmades[0]$currentmonths=$datepaymentmades[1]$当前年份=$currentyears$currentmonth=$currentmonths;并使用$currentyear=date('Y')$当前月份=日期('m');然后我可以打开页面,但我不想要系统日期我想要使用我选择的日期你能改变这行并删除
true
像这样
$dataee['payment\u date']=$this->input->post('payment\u date')好的,让我们调试一下,你能回显一下吗,请告诉我。
$paymentDate = strtotime($dataee['payment_date']);
$month = date("m",strtotime($paymentDate));
$year = date("Y",strtotime($paymentDate));
$day = date("d",strtotime($paymentDate));