Return counter 0 from FROM_UNIXTIME

Background

This is an API that supports the installation of Highcharts interfaces. The user has the opportunity to select the "day" (24 hours), week (7 days) or user interval without restrictions. The x axis (dates / times) must be fully dynamic due to the nature of the selected date range (this has been completed).

Y axis

The way we calculate X-Axis (dates) works very well, but we are having trouble returning a value of zero on a specific day.

We use this query to calculate the values:

SELECT COUNT(u.videoid)                   AS metric, 
       FROM_UNIXTIME(u.TIME, '%M %e, %Y') AS `sqltime` 
FROM   videos u 
WHERE  ( u.TIME >= 1291179600 
         AND u.TIME <= 1293858000 ) 
       AND u.channel = '48' 
GROUP  BY `sqltime` 
ORDER  BY `sqltime` ASC

Here is an example output:

metric  sqltime 
2   December 13, 2010
9   December 14, 2010
1   December 15, 2010
7   December 16, 2010
32  December 17, 2010
10  December 18, 2010
6   December 19, 2010
17  December 20, 2010
19  December 21, 2010
10  December 22, 2010
20  December 23, 2010
8   December 24, 2010
9   December 26, 2010
33  December 27, 2010
29  December 28, 2010
24  December 29, 2010
34  December 30, 2010
11  December 31, 2010

The problem is that it does not return the value on December 25th (with 0 as the metric value). This causes Highcharts to completely skip the value, instead of showing 0. So, what the chart looks like:

Sample

: Corrected

. - 0 25 2010 ( ).

, : , 0, videos / WHERE?

x:

    public function getCordinateCount()
    {
        $totalTime = $this->endTime - $this->startTime;

        // 86400 seconds in a day.
        $days = ceil($totalTime / 86400);

        if($days <= 1) {
            return 'FROM_UNIXTIME( u.time, \'%M %e, %Y %H:00\') AS `sqltime`';
        } elseif ($days < 60) {
            return 'FROM_UNIXTIME( u.time, \'%M %e, %Y\') AS `sqltime`';
        } else {

            return 'DATE_FORMAT(
                        SUBDATE(
                          FROM_UNIXTIME( u.time ),
                          INTERVAL WEEKDAY( FROM_UNIXTIME( u.time ) ) DAY
                        ),
                        \'%M %e, %Y\') as `sqltime`';
        } 

    }
+3
1

DAYS ( 1 31 ).

. , ZERO = >

SELECT IF(tmp.metric IS NULL,0,tmp.metric),DAYS.datestr FROM DAYS LEFT JOIN (
SELECT COUNT(u.videoid)                   AS metric, 
       FROM_UNIXTIME(u.TIME, '%M %e, %Y') AS `sqltime` 
FROM   videos u 
WHERE  ( u.TIME >= 1291179600 
         AND u.TIME <= 1293858000 ) 
       AND u.channel = '48' 
GROUP  BY `sqltime` 
) tmp ON DAYS.datestr=tmp.`sqltime`
ORDER  BY `sqltime` ASC

( , DAYS.datestr , sqltime).

QUERY. PHP, 0 , .

...

0

All Articles