简体   繁体   中英

Doctrine query group by date

I am building an application and I want some sort of notification / log type of page intergrated where the user can see his activity. The page needs to look like the following example:

Today  
[Username] has done [activity] 13:20  
[Username] has done [activity]  11:27  
[Username] has done [activity]  10:53  

Yesterday   
[Username] has done [activity]  13:20  
[Username] has done [activity]  11:27  
[Username] has done [activity]  10:53  

14 februari  
[Username] has done [activity]  13:20  
[Username] has done [activity]  11:27  
[Username] has done [activity]  10:53  

The thing is that I have absolutely no idea where to start. I am thinking of some kind of log table and then log everything that happens in a table. But how do I need to query to get the above result? I really need someone or something to point me to the right direction.

you are on the right direction : Just create your log table like this:

create table log(
id int not null primary key identity(1,1),
userID int not null,
logdate datetime,
activityID int not null)

assuming you have a users table that contain the users and a Activity table that contains all the possible activities

then you can produce your query joining the 3 tables:

select * 
from log l 
     join UserTable u on l.userId=u.UserId 
     join ActivityTable a on l.ActivityId=a.ActivityID

and then format your text based on the select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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