cakephp组

yk9xbfzb  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(322)

我有一张table,上面写着日期。。。我想返回一个表,它按日期给我一个commande组,但我的问题是,每个日期都有一个commande,当我在那个日期有多个commande时,她是我的请求:

$factures = $this->Commande->find('all', array(

                    'conditions' => array(
                        'Commande.prestataire_id' => $this->request->data['prestataire_id']

                    ),
             'group' => array('Commande.date'),
                 'order' => array('Commande.date' => 'DESC'),
                 'fields' => array(' Commande.date'),
                ));

以下是输出:

{
    "status": "Success",
    "status_code": 200,
    "message": "Commande trouvé",
    "data": {
        "everjob_get_Mission": {
            "data": [
                {
                    "Commande": {
                        "date": "2018-04-25"
                    }
                },
                {
                    "Commande": {
                        "date": "2018-04-24"
                    }
                },
                {
                    "Commande": {
                        "date": "2018-04-23"
                    }
                },
                {
                    "Commande": {
                        "date": "2018-04-19"
                    }
                },
                {
                    "Commande": {
                        "date": "2018-04-20"
                    }
                }
            ]
        }
    }
}
q35jwt9p

q35jwt9p1#

试着用下面的代码。我希望它对你的工作没有把握。

$factures = $this->Commande->find('all', array(
        'fields' => 'DISTINCT Commande.date',
        'conditions' => array(
            'Commande.prestataire_id' => $this->request->data['prestataire_id']

        ),
    'group' => array('Commande.date'),
    'order' => array('Commande.date' => 'DESC')
));

相关问题