brown2005 Posted March 12, 2008 Share Posted March 12, 2008 $x = "30"; $sql = "SELECT COUNT(*) AS members_count FROM members WHERE ( code here )"; now where code here is.. i want to select all members who have logged in in $x days with members_login being the field with the date... thanks in advance Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 12, 2008 Share Posted March 12, 2008 <?php $x = "30"; $sql = "SELECT COUNT(*) AS members_count FROM members WHERE members_login < (NOW() - INTERVAL $x DAY)"; ?> Quote Link to comment Share on other sites More sharing options...
brown2005 Posted March 12, 2008 Author Share Posted March 12, 2008 hi thanks for the help, but that returns a 0 count Quote Link to comment Share on other sites More sharing options...
brown2005 Posted March 12, 2008 Author Share Posted March 12, 2008 1 2008-03-12 17:22:43 2 2008-03-12 17:22:43 3 2008-02-11 17:22:43 i have the above 3 results in my table.. and it comes up with 1.. which is number 3... which is out of 30 days. the code above looks like it gives all members that have logged in before $x amount of days.. but i want from $x days to now.... any ideas would be much appreciated.. thanks in advance. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 12, 2008 Share Posted March 12, 2008 Try changing the query to: SELECT COUNT(*) AS members_count FROM members WHERE members_login <= (NOW() - INTERVAL $x DAY) Quote Link to comment Share on other sites More sharing options...
brown2005 Posted March 12, 2008 Author Share Posted March 12, 2008 nope still 1... wat does <= (NOW() - INTERVAL $x DAY) actually mean? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted March 12, 2008 Share Posted March 12, 2008 This part: members_login <= (NOW() - INTERVAL $x DAY) means If the date members_login is less than or equal to x days ago. I think I got the symbol messed up and turned the wrong way So change it to this: SELECT COUNT(*) AS members_count FROM members WHERE members_login >= (NOW() - INTERVAL $x DAY) Quote Link to comment Share on other sites More sharing options...
brown2005 Posted March 12, 2008 Author Share Posted March 12, 2008 yes that works.. why on earth did i not spot that..... tut tut.. anyway thanks very much 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.