eddieblunt Posted October 16, 2008 Share Posted October 16, 2008 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"; Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/ Share on other sites More sharing options...
AV1611 Posted October 16, 2008 Share Posted October 16, 2008 date('Y-m-d H:i:s', $timestamp); there's a hint Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667321 Share on other sites More sharing options...
eddieblunt Posted October 16, 2008 Author Share Posted October 16, 2008 Is that all you can give me? Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667324 Share on other sites More sharing options...
AV1611 Posted October 16, 2008 Share Posted October 16, 2008 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..." Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667327 Share on other sites More sharing options...
Barand Posted October 16, 2008 Share Posted October 16, 2008 You could SELECT id, picture, user, title, DATE_FORMAT(published,'%M %Y') FROM ... which will give dates in "October 2008" format Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667328 Share on other sites More sharing options...
eddieblunt Posted October 16, 2008 Author Share Posted October 16, 2008 AV1611 I was thinking, just links with each month at the top of the archive page and have the link read something like: http://www.example.com/2008archive.php?month=Jan Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667332 Share on other sites More sharing options...
Barand Posted October 16, 2008 Share Posted October 16, 2008 Make that "?month=1" $month = $_GET['month']; $year = date('Y'); // current year then SELECT ... WHERE MONTH(published) = $month AND YEAR(published) = $year Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667334 Share on other sites More sharing options...
AV1611 Posted October 16, 2008 Share Posted October 16, 2008 My way would work but Barand is sooo much smarter than me Do it his way Hey Barand! Long time no see! Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667338 Share on other sites More sharing options...
eddieblunt Posted October 16, 2008 Author Share Posted October 16, 2008 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 Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667343 Share on other sites More sharing options...
Barand Posted October 16, 2008 Share Posted October 16, 2008 WHERE MONTH(FROM_UNIXTIME(published)) = $month Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667344 Share on other sites More sharing options...
eddieblunt Posted October 16, 2008 Author Share Posted October 16, 2008 Genius!! Thats done it, thanks for all your help!! Link to comment https://forums.phpfreaks.com/topic/128748-solved-display-mysql-table-data-by-month-with-php/#findComment-667349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.