poe Posted March 9, 2007 Share Posted March 9, 2007 my table has: id | user | month | year 1 | chris | 6 | 2006 2 | chris | 12 | 2006 3 | chris | 1 | 2007 4 | mary | 6 | 2007 5 | mary | 11 | 2007 6 | chris | 8 | 2007 7 | chris | 9 | 2007 8 | chris | 1 | 2008 9 | chris | 4 | 2008 how do i select just the records that belong to a certain user 'chris' that are months in the future so since 2006 has passed, id 1, id 2 will be skipped, id3 will also skip Quote Link to comment Share on other sites More sharing options...
btherl Posted March 9, 2007 Share Posted March 9, 2007 It would be easier if you used a date data type instead.. but since you've got integers (are they integers? or varchars?), you can do $cur_month = date('m'); $cur_year = date('Y'); $sql = "SELECT * FROM table WHERE user = 'chris' AND (year > $cur_year OR (month > $cur_month AND year = $cur_year))"; You can also fetch the date from within mysql, but I'm not familiar with how to do that. Edit: Oops.. fixed silly mistake Quote Link to comment Share on other sites More sharing options...
fenway Posted March 9, 2007 Share Posted March 9, 2007 Yeah, much easier with dates... and mysql will even let you store incomplete ones, like 2006-01-00. Quote Link to comment Share on other sites More sharing options...
poe Posted March 21, 2007 Author Share Posted March 21, 2007 ok thanks, i will have to try that Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.