Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CakePHP重建查询_Cakephp_Cakephp 2.0 - Fatal编程技术网

使用CakePHP重建查询

使用CakePHP重建查询,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我目前有: $firstDay = new DateTime('first day of this month 00:00:00'); $lastDay = new DateTime('first day of this month 00:00:00'); return $this->Visitor->query( "SELECT (? + INTERVAL c.day - 1 DAY) unix_ts_day,

我目前有:

    $firstDay = new DateTime('first day of this month 00:00:00');
    $lastDay = new DateTime('first day of this month 00:00:00');

    return $this->Visitor->query(
        "SELECT
          (? + INTERVAL c.day - 1 DAY) unix_ts_day,
          COUNT(v.site_id) as visit_count
        FROM
          calendar c
        LEFT JOIN (
          SELECT * FROM visitors
            WHERE site_id = ? AND DATE(created) BETWEEN ? AND ?
          ) v
          ON DAYOFMONTH(v.created) = c.day
        GROUP BY
          unix_ts_day", array(
            $firstDay->format('Y-m-01' ),
            $this->id,
            $firstDay->format('Y-m-01' ),
            $lastDay->format('Y-m-t' )
        )
    );
我的桌子:

Calendar

id  | day
---------
1   | 1
2   | 2
3   | 3
...
31  | 31

Visitors

id  | site_id | created
-----------------------------------
1   | 16      | 2012-10-18 11:14:39
2   | 16      | 2012-10-18 11:15:17
3   | 11      | 2012-10-18 11:49:14
4   | 11      | 2012-10-18 11:49:43
5   | 16      | 2012-10-19 11:54:37
6   | 1       | 2012-10-19 05:56:31
7   | 2       | 2012-10-19 05:57:56
现在,日历表(没有日历模型)与访问者表没有关联


当上述查询工作时。我在想,如果这是CakePHP类可以做的事情,而不是我调用
query
方法。如何更改此项以使用它?

日历和访客表之间的关系是什么?实际上没有。我使用Calendar表输出31条记录,这些记录表示日历月的天数,然后将其连接到visitors表