iChriss Posted January 21, 2011 Share Posted January 21, 2011 Hello everyone I am coding a membership system for my usersystem on my website and I needed a little help. I have searched around quite a bit and can't find a working code. In my database I have the date the VIP was purchased and I was wondering if anyone had a code which would check if they've had VIP for over a month and if so, delete it from the database. I'm new-ish to MySQL and PHP and can't seem to code a working one. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 21, 2011 Share Posted January 21, 2011 name of field and type? Quote Link to comment Share on other sites More sharing options...
iChriss Posted January 21, 2011 Author Share Posted January 21, 2011 username (The user's username) rank ( 1= Normal User 2= VIP) vip_purchased (The date the VIP was purchased, preferably in the format: Y/m/d) They are all VARCHAR but I can change/add anything if needed So I want the rank to change back to 1 after a month has passed since vip_purchased Quote Link to comment Share on other sites More sharing options...
Valakai Posted January 21, 2011 Share Posted January 21, 2011 I would store the vip_purchased as an int(10) and populate it with the time() function at the time of purchase You can then check when 1 month has passed with this code // (time() - $vip_purchased) - Number of seconds since time of purchase // (60*60*24*31) - Number of seconds in 31 days if(((time() - $vip_purchased) > (60*60*24*31)) { // VIP Time Expired } Quote Link to comment Share on other sites More sharing options...
Valakai Posted January 21, 2011 Share Posted January 21, 2011 If you want to keep the format Y/m/d, you can use the date() function on the $vip_purchased timestamp. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 21, 2011 Share Posted January 21, 2011 I would suggest using datetime for your date field, much easier to do comparisons, search upon and format output. 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.