Cake is stuck in query setup.(I want to display the latest date of the month.)

Asked 5 months ago, Updated 5 months ago, 13 views

Hello, I'm a beginner at cake.I have a question because I am stuck with the query settings.

Here's what you want to do:

Displays the most recent date of the month.

I am writing a custom query as follows:

        'limit' = > 20,
        'group' = > ['date' = > 'month(date)' ]


The results are as follows:

November 02, 2016 (smallest date)
October 01, 2016 (smallest date)
September 21, 2016 (smallest date)

What do you want to do

November 05, 2016 (date is up to date)
October 05, 2016 (date is up to date)
September 30, 2016 (date is up to date)

What do you want to hear

·Whether or not the latest date can be displayed successfully just by setting the paginate.
·Is there any other better way?

Thank you for your cooperation.

php mysql cakephp

2022-09-30 14:12

1 Answers

The solution is as follows:
Implemented in the query builder
To set max(date), get query and set select.

$query=$this->Table->find();// query retrieval
Specify 'date'=>$query->func()->max('date')//max(date)
        'limit' = > 20,
        'group' = > ['date' = > 'month(date)' ]


I couldn't solve myself.

2022-09-30 14:12

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.