Jump to content

[SOLVED] Display MYSQL table data by month with PHP?


eddieblunt

Recommended Posts

Hi,

I've got an image gallery where users can login and upload images. When an images is published it updates the "published" column with the current Unix timestamp

 

I want to be able to display the images on an archive page to view the uploads by month

 

Any ideas on how i should do this?

 

Here's my query string:

 

$query = "SELECT id, picture, user, title, published". 
         "FROM uploads". 
         "WHERE published is not null ".
         "ORDER BY published DESC ".  
         "LIMIT $offset, $rowsPerPage";

I really suck at dates myself.

 

If I understand you want to search for a given month? or loop through each month. If the latter, that's separate I think.

Either way, There are several ways I suppose but I would prolly determine the unix timestamp for the 1st day and last day of the month (midnight respectively) and add something like

"... WHERE field >= $monthstart AND field <= $monthend..."

 

 

That doesn't seem to work?

 

My dates are stored in my database as "1200350730" for example, which is 14/01/08

 

does the

WHERE MONTH(published) = $month

know this?

 

 

I've also tried with and without the DATE_FORMAT on the SELECT line

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.