Jump to content

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

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.