-3

I want the array to be divided into days of the week according to the date specified in BETWEEN and AND

public static function showDataByEmployer($employer)
 {


    $sql = 'SELECT `WorkingDay` 
            FROM `status` 
            WHERE `WorkingDay` BETWEEN "2021-04-12" AND "2021-04-16" 
                   AND NameFinish = :employer ';

    $db = static::getDB();
    $stmt = $db->prepare($sql);
    $stmt->bindValue(':employer', $employer, PDO::PARAM_STR);
    
    $stmt->execute();
    $user_data = $stmt->fetchAll();

    print_r($user_data);
 }

What is the best way to display the data in an array by day of the week. My example :

Array
(
    [0] => Array 
        (
            [0] => Array
                (
                    [WorkingDay] => 2021-04-12 00:00:00
                    [0] => 2021-04-12 00:00:00
                )

            [1] => Array
                (
                    [WorkingDay] => 2021-04-12 00:00:00
                    [0] => 2021-04-12 00:00:00
                )

            [2] => Array
                (
                    [WorkingDay] => 2021-04-12 00:00:00
                    [0] => 2021-04-12 00:00:00
                )
        ) 
        
    [1]=> Array
        (
            [0] => Array
                (
                    [WorkingDay] => 2021-04-13 00:00:00
                    [0] => 2021-04-13 00:00:00
                )

            [1] => Array
                (
                    [WorkingDay] => 2021-04-13 00:00:00
                    [0] => 2021-04-13 00:00:00
                )

            [2] => Array
                (
                    [WorkingDay] => 2021-04-13 00:00:00
                    [0] => 2021-04-13 00:00:00
                )
        )      

)

Where [0] is monday 12-04, [1] is Tuesday 13-04 ect.

  • Did you already read: [How can I group by date time column without taking time into consideration](https://stackoverflow.com/q/6054144/2943403) and [Group by date without time](https://stackoverflow.com/q/30988419/2943403) and [sql group by date without time](https://stackoverflow.com/q/26096840/2943403) and [Group by date only on a Datetime column](https://stackoverflow.com/q/366603/2943403) and [using date of datetime in group by and order by in single SELECT versus using subquery](https://stackoverflow.com/q/66311647/2943403)? – mickmackusa May 12 '22 at 01:31
  • Why aren't `$workDayStart` and `$workDayEnd` method parameters? Are you already compensating for the fact that the end date will not be inclusive? ...meaning are you bumping the end date by +1 day? I recommend that you use newlines in your sql declaration so that your code does not require horizontal scrolling to read. I typically separate each clause on a new line. `SELECT` clause on one line, `FROM` on the next, `WHERE` on the next, etc. – mickmackusa May 12 '22 at 01:37

0 Answers0