0
我有兩列名稱類型日期的'開始'和'結束'。我想循環遍歷從開始到結束的日期,並根據月份在表中插入一些數據。 我嘗試了下面的代碼,但沒有插入我的表中。循環通過開始日期到結束日期
這裏是我的代碼:
$session_info = $this->db->get_where('session', array('componentId' => $session_id))->row_array();
$start = strtotime($session_info['start']);
$end = strtotime($session_info['end']);
$fee_classwise = $this->db->get_where('fee_conf', array('class_id' => $class_id))->result_array();
foreach ($fee_classwise as $row) {
$feeInfo = $this->db->get_where('item', array('componentId' => $row['item_id']))->row_array();
if($feeInfo['category3']=='ONCE') {
$dataFee['studentFeeName'] = $feeInfo['itemName'];
$dataFee['studentId'] = $student_id;
$dataFee['sessionId'] = $running_year;
$dataFee['itemId'] = $feeInfo['componentId'];
$dataFee['amount'] = $feeInfo['salePrice'];
$dataFee['month'] = date('F', $start);
$dataFee['year'] = date('Y', $end);
$this->db->insert('student_feeconfig', $dataFee);
}
if($feeInfo['category3']=='SESSION') {
$session_start = $start;
$session_end = $end;
while($session_start < $session_end) {
$dataFee['studentFeeName'] = $feeInfo['itemName'].'-'.date('M', $session_start);
$dataFee['studentId'] = $student_id;
$dataFee['sessionId'] = $session_id;
$dataFee['itemId'] = $feeInfo['componentId'];
$dataFee['amount'] = $feeInfo['salePrice'];
$dataFee['month'] = date('F', $session_start);
$dataFee['year'] = date('Y', $session_start);
$this->db->insert('student_feeconfig', $dataFee);
$session_start = strtotime('+4 month', $session_start);
}
}
if($feeInfo['category3']=='MONTHLY') {
$month_start = $start;
$month_end = $end;
while($month_start < $month_end) {
$dataFee['studentFeeName'] = $feeInfo['itemName'] .'-'. date('M', $month_start);
$dataFee['studentId'] = $student_id;
$dataFee['sessionId'] = $session_id;
$dataFee['itemId'] = $feeInfo['componentId'];
$dataFee['amount'] = $feeInfo['salePrice'];
$dataFee['month'] = date('F', $month_start);
$dataFee['year'] = date('Y', $month_start);
$this->db->insert('student_feeconfig', $dataFee);
$month_start = strtotime('+1 month', $month_start);
}
}
}