brmcdani Posted May 18, 2010 Share Posted May 18, 2010 I am trying to create a mysql statment where the following records are pulled out based on which month it is. The following statment I have will pull out the latest photos and order them by the date. However I want it to pull out records only from the current month. Any ideas will be appreciated. Thanks $sql="select * from members,photos where members.username=photos.username and approved='Y' and active=1 order by photos.upldate"; Link to comment https://forums.phpfreaks.com/topic/202187-order-by-record-within-month/ Share on other sites More sharing options...
Mchl Posted May 18, 2010 Share Posted May 18, 2010 $sql=" SELECT * FROM members AS m INNER JOIN photos AS p ON m.username=p.username WHERE approved='Y' AND active=1 AND MONTH(p.upldate) = MONTH(CURDATE()) ORDER BY p.upldate DESC"; Link to comment https://forums.phpfreaks.com/topic/202187-order-by-record-within-month/#findComment-1060237 Share on other sites More sharing options...
brmcdani Posted May 18, 2010 Author Share Posted May 18, 2010 Thanks I got figured it out as soon as you posted. Here was my solution: $sql="select * from members,photos WHERE members.username=photos.username and YEAR(upldate) = YEAR(CURDATE()) AND MONTH(upldate) = MONTH(CURDATE()) and approved='Y' and active=1 order by photos.upldate"; Link to comment https://forums.phpfreaks.com/topic/202187-order-by-record-within-month/#findComment-1060241 Share on other sites More sharing options...
Mchl Posted May 18, 2010 Share Posted May 18, 2010 Right. Forgot about a year Link to comment https://forums.phpfreaks.com/topic/202187-order-by-record-within-month/#findComment-1060246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.