Jump to content

ordering rows by year/month loop


nothingatall

Recommended Posts

Okay, so im really not sure on this one, even though it is the simplest thing.

 

I need to pull out of my table each row, and have them ordered via year/month. ie once it gets the first year it shows a column for each month where there is data, then the next month and so on...

 

i have each row with a unix timestamp

and i know what i want to do, but whatever i do i cant do!

any really simple help would be hugely appreciated!

Link to comment
https://forums.phpfreaks.com/topic/161051-ordering-rows-by-yearmonth-loop/
Share on other sites

The main reason you could not find an easy solution is because a Unix Timestamp does not lend itself to uses where you must get the year/month out of it. It must undergo a (slow) conversion to be used for most purposes or even to display it in a human readable form.

 

If you can, change your field to a standard DATETIME data type. If you must keep it as a Unix Timestamp, look at the mysql FROM_UNIXTIME() function using the second parameter to let you extract the month and year (separately, using two calls to FROM_UNIXTIME()) in your SELECT term that you can then use in your presentation code to do what you are asking.

 

The main reason you could not find an easy solution is because a Unix Timestamp does not lend itself to uses where you must get the year/month out of it. It must undergo a (slow) conversion to be used for most purposes or even to display it in a human readable form.

 

yeah, i pretty much worked that out, unfortunatly im gonna have to use from_unixtime() i think. simple things are always the hardest! thanks for the advice

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.