I'm trying to get data for a current week from MYSQL Database and dates are in milliseconds, and i'm using SLIM framework, When i display data i get result but it display all the days repeated. My code are

$app->get('/view/test/days', function ($request, $response, array $args) {
    try {
        $con = $this->db;
        // date_default_timezone_set('EAT');
        $sql = "SELECT start_time,COUNT(*) as tt FROM parking_sessions 
GROUP BY DAY(DATE (FROM_UNIXTIME(start_time/1000))),YEAR(DATE 
(FROM_UNIXTIME(start_time/1000)))";
        $result = null;
        $results = null;
        $tt = null;
        foreach ($con->query($sql) as $row) {

            $result[] = date('D',($row['start_time']/1000));
            $tt[] = $row['tt']; 
            $results['date'] =$result;

            $results['total'] =$tt; 
        }
        if ($result) {
            return $response->withJson(array('status' => 'true', 'date' => $results), 200);
        } else {
            return $response->withJson(array('status' => 'Owner Not Found'), 422);
        }

    } catch (\Exception $ex) {
        return $response->withJson(array('error' => $ex->getMessage()), 422);
    }
});

And it give me the following result

{
"status": "true",
"date": {
    "date": [
        "Thu","Fri","Sun","Mon","Thu","Mon","Sat","Sun","Thu","Tue","Sun"
    ],
    "total": [
        "1","1","1","1","3","1","14","1","5","2","1"
    ]
}
}

And all result needed is only for current week

    {
"status": "true",
"date": {
    "date": [
        "Sun","Thu","Tue","Sun"
    ],
    "total": [
        "1","5","2","1"
    ]
}
}

My Database are Like

  id slot_id    customer_vehicle_id    start_time        end_time             check_out_time      status


1    1              2                1553249524000     1554346841515            1553111000          1

2    6              4                1554351619803     1553253124000            1553214094          0

3    6              4                1555224715000     1553253124000            1553214094          0

4    7              3                5086800000        1553253124000            1553214094          0

0 Answers