3raser Posted May 2, 2010 Share Posted May 2, 2010 Hey! I've always wondered about this, and I've always thought this would become handy if I ever wanted to create a big website. How do I make it so after 24 hours, their be a change in the database? Example of what I mean: You vote for something, and you must wait 24 hours before voting again. You visit the next day, 24 hours+, and it lets you vote. How would I make something like this? Quote Link to comment https://forums.phpfreaks.com/topic/200415-automatic-time-updating/ Share on other sites More sharing options...
andrewgauger Posted May 2, 2010 Share Posted May 2, 2010 Put a timestamp in the table (default to NOW) and compare the values before updating. Quote Link to comment https://forums.phpfreaks.com/topic/200415-automatic-time-updating/#findComment-1051735 Share on other sites More sharing options...
3raser Posted May 2, 2010 Author Share Posted May 2, 2010 Put a timestamp in the table (default to NOW) and compare the values before updating. Understandable. But how would I compare them? Quote Link to comment https://forums.phpfreaks.com/topic/200415-automatic-time-updating/#findComment-1051797 Share on other sites More sharing options...
andrewgauger Posted May 2, 2010 Share Posted May 2, 2010 Well a timestamp is simply the number of seconds since (appx) 1970. So if you take the value stored in the database and add 86400 to it, you can then: $result=mysql_fetch_array(mysql_query("SELECT time FROM table_name WHERE condition"))); if ($result[0]+86400 < time()){ //todo: write the code that is acceptable after 24 hours } Quote Link to comment https://forums.phpfreaks.com/topic/200415-automatic-time-updating/#findComment-1051799 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Example: SELECT COUNT(*) c FROM table WHERE DATE_SUB(CURDATE(), INTERVAL 1 DAY) <= timestamp_column AND userid = 1; Take a look here - http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html It has tons of useful functions for you to pick at. Quote Link to comment https://forums.phpfreaks.com/topic/200415-automatic-time-updating/#findComment-1051800 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.