Jump to content

Group by date


doddsey_65

Recommended Posts

im building an alert system where all alerts for the current user are listed. What i would like though is for the alerts to be grouped under the date they were added to the database.

 

For example this is how it displays now, its just a list:

 

alert1
alert2
alert3

 

but i would like it like this:

 

29th July
alert1
alert2

28th July
alert3
alert4
alert5

 

Anyone have any idea how i may go about it? I have a date column(UNIX timestamp) in the database for the alerts but it wouldnt be grouping using the SQL would it?

 

Link to comment
https://forums.phpfreaks.com/topic/243177-group-by-date/
Share on other sites

Unfortunately Unix Timestamps are the worst way of storing data that you need to manipulate using human calendar units (days, weeks, months, years) because you must perform a (relatively slow) conversion on all the data to get it into a format where you can perform the needed manipulation.

 

If you use the mysql FROM_UNIXTIME(unix_timestamp,format) function in your query to convert and select the date in the format you want, you can then detect in your php code when the date changes and output a new date heading followed by the values under each date.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/243177-group-by-date/#findComment-1249026
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.