我有一个名为 tblprocesstimekeeping 的表,其中包含以下数据:
假设我有一个日期范围2019-05-01 - 2019-05-15
我想要做的是在每个 empCompID 的 tblprocesstimekeeping 数据中的给定范围之间插入缺失的日期。
这是我的代码:
$begin = new DateTime('2019-05-01'); // Get Begin Date
$end = new DateTime('2019-05-15'); // Get End Date
$end = $end->modify( '+1 day' ); // Increment +1 Day
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end); // Get Date Range
foreach($daterange as $date){
$dateNumber = $date->format("Y-m-d"); // counter date + 1 day
//Select company access id and date from tblprocesstimekeeping
$query = $this->db->query("SELECT * FROM tblprocesstimekeeping where companyAccessID = '$companyAccessID'");
foreach ($query->result() as $row){
$empCompID = $row->empCompID;
$date = $row->date;
//echo $date .' = '. $empCompID.'<br>';
if ($date == $dateNumber) {
echo $date .' = '. $empCompID.' = GOOD <br>';
} else{
echo $dateNumber .' = '. $empCompID.' = NO DATA <br>';
}
}
}
输出应该是:
2019-05-01 = 11007 - NO DATA
2019-05-01 = 20003 - NO DATA
2019-05-02 = 11007 - GOOD
2019-05-02 = 20003 - GOOD
2019-05-03 = 11007 - GOOD
2019-05-03 = 20003 - GOOD
2019-05-04 = 11007 - GOOD
2019-05-04 = 20003 - GOOD
2019-05-05 = 11007 - NO DATA
2019-05-05 = 20003 - NO DATA
2019-05-06 = 11007 - NO DATA
2019-05-06 = 20003 - GOOD
2019-05-07 = 11007 - GOOD
2019-05-07 = 20003 - GOOD
2019-05-08 = 11007 - GOOD
2019-05-08 = 20003 - GOOD
2019-05-09 = 11007 - GOOD
2019-05-09 = 20003 - GOOD
2019-05-10 = 11007 - GOOD
2019-05-10 = 20003 - GOOD
2019-05-11 = 11007 - GOOD
2019-05-11 = 20003 - GOOD
2019-05-12 = 11007 - NO DATA
2019-05-12 = 20003 - NO DATA
2019-05-13 = 11007 - NO DATA
2019-05-13 = 20003 - NO DATA
2019-05-14 = 11007 - GOOD
2019-05-14 = 20003 - GOOD
2019-05-15 = 11007 - GOOD
2019-05-15 = 20003 - GOOD
不负相思意
守着一只汪