简体   繁体   English

cakePHP中的联接和计数表

[英]Join and Count Tables in cakePHP

thanks to the help i have gotten on Stackoverflow while learning php i am able to Join tables and use Count. 多亏了我在学习PHP的同时获得Stackoverflow的帮助,我能够加入表并使用Count。

I am unable to do both in one query. 我无法在一个查询中同时执行这两个操作。

I am wanting to count records in a joined table. 我想计算联接表中的记录。 This is what i have tryed and i seem to get errors: 这是我尝试过的,但似乎出现错误:

$options = array(
    'fields' => array(
        'toutcome.AffCommission',
    ),
    'joins' => array(

        array(
            'conditions' => array(
                'tapplicant.AppID = toutcome.AppID',
            ),
            'table' => 'toutcome',
            'alias' => 'Toutcome',
            'type' => 'join',
        ),
    ),
    'limit' => 'Toutcome',
    'offset' => 'Toutcome',
    'contain' => array(
        'Toutcome',
    ),
);

$data = $this->Tapplicant->find('count', $options);
$this->set('count', $data );

Try this 尝试这个

$options = array(
    'fields' => array(
        'toutcome.AffCommission',
    ),
    'joins' => array(

        array(
            'conditions' => array(
                'tapplicant.AppID = toutcome.AppID',
            ),
            'table' => 'toutcome',
            'alias' => 'Toutcome',
            'type' => 'join',
        ),
    ),
    'limit' => n, // its should be integer
    'offset' => n, // its should be integer
    'contain' => array(
        'Toutcome',
    ),
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM