I'm currently working on a small production tracker to make my life easier at work, all going well so far but i'm hitting a wall when it comes to getting some statistics.
I'm trying to count all rows with monday-sundays dates and between certain hours to denote day/night shifts.
Below is what I have so far, the issue I'm having is the only query that seems to be working is Days and even that seems to only want to output Sundays (today) count, everything else is coming back as 0. echoing the $key or $value foreach comes out correct though.
Thanks for any help.
$this_week = array($monday=>"monday", $tuesday=>"tuesday", $wednesday=>"wednesday", $thursday=>"thursday", $friday=>"friday", $saturday=>"saturday", $sunday=>"sunday");
foreach ($this_week as $key => $value) {
// Days
$sql_day = "SELECT count(*) FROM `stage_tbl` WHERE stage_1_date = :datenow AND stage_1_time BETWEEN :day_start AND :day_end";
$result_day = $conn->prepare($sql_day);
$result_day->execute(array ('datenow' => $key, 'day_start' => $day_start, 'day_end' => $day_end));
$number_of_rows_day = $result_day->fetchColumn();
$day = "{$value}_day";
$$day = $number_of_rows_day;
// Nights
$datenext = date('Y-m-d', strtotime($key. ' + 1 days'));
$sql_night = "SELECT count(*) FROM `stage_tbl` WHERE stage_1_date = :datenow AND stage_1_time >= :night_start OR WHERE stage_1_date = :datenext AND stage_1_time <= :night_end";
$result_night = $conn->prepare($sql_night);
$result_night->execute(array ('datenow' => $key, 'night_start' => $night_start, 'night_end' => $night_end, 'datenext' => $datenext));
$number_of_rows_night = $result_night->fetchColumn();
$night = "{$value}_night";
$$night = $number_of_rows_night;
}