Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Grouping query results by date
  • Hello.

    Maybe someone can help me to solve this, please.

    I have this table:
    image
    I would like to group in the final view, all records with an specific horse_id, which is simple to do, but i would like also to group by date of creation (exactly by each diferent day).

    In example:

    I have this 5 records: (created_by is unix time, but for easy undertsanding AND already filtered for horse_id = 20)

    id |  Body     |  Horse_id | created_at 
    1 | Body of 1 |     20      | 10/05/2013 10:22
    2 | Body of 2 |     20      |  12/05/2013 12:05
    3 | Body of 3 |     20      | 10/05/2013  16:22
    4 | Body of 4 |      20     | 12/05/2013 02:12
    5 | Body of 5 |     20      | 10/05/2013 09:19

    As you can see, there are 5 records with a horse_id = 20, but every record has a different creation date, what i want to do is in the final view, show all records by the specific horse (horse_id = 20) but grouped by the day of creation and then sorted by time of the day:

    All records with horses_id = 20:

    10/05/2013
    09:19
    10:22
    16:22

    12/05/2013
    02:12
    12:05

    Well thats it, i dont know how to handle that, the idea is to do an collapsible menu, which each day could be expanded showing then all the different records of that day.

    Thank you very much in advanced, hopw its well explained 

  • HarroHarro
    Accepted Answer
    Something like:

    SELECT *, DATE_FORMAT(created_at,GET_FORMAT(DATE,'ISO')) AS Date, DATE_FORMAT(created_at, '%H:%i') as Time  FROM table GROUP BY Horse_id, Date

    ?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion