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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.