I'm trying to insert an array of dates in database but the program does not behave. I'm doing something wrong.
This insert NULL:
// initialize the array with first date
$dates = array(strtotime("+17 days", strtotime($period_startdate)));
// now loop 26 times to get the next 26 dates
for ($i = 1; $i <= 26; $i++) {
// add 14 days to previous date in the array
$dates[] = strtotime("+14 days", $dates[$i-1]);
}
// echo the results
foreach ($dates as $date) {
// prepare and bind for paydates
$insertpaydates= $db->prepare("INSERT INTO paydates (payroll_secret_id,paydate) VALUES (?,?)");
$insertpaydates->bind_param("ss",$secret_id,$dates[$date]);
}
This insert only one row and wrong date (1970-01-01)
// initialize the array with first date
$dates = array(strtotime("+17 days", strtotime($period_startdate)));
// now loop 26 times to get the next 26 dates
for ($i = 1; $i <= 26; $i++) {
// add 14 days to previous date in the array
$dates[] = strtotime("+14 days", $dates[$i-1]);
}
// echo the results
foreach ($dates as $date) {
$Item_Date[$date] = date("Y-m-d", strtotime($Item_Date[$date]));
// prepare and bind for paydates
$insertpaydates= $db->prepare("INSERT INTO paydates (payroll_secret_id,paydate) VALUES (?,?)");
$insertpaydates->bind_param("ss",$secret_id,$Item_Date[$date] );
}
$period_startdate?