fantity Posted November 11, 2012 Share Posted November 11, 2012 I am making a toplist for a game and users can vote their favorite one up every 24 hours. This is the mysql table: Here is an example entry: As you can see it was made on November 9th. Here is the code when they try to go to vote.php if they voted within 24 hours. $result = mysql_query("SELECT * from votes WHERE time > UNIX_TIMESTAMP() - 3600 * 24 AND name='$uname'"); if(mysql_num_rows($result)==1){ header("location:voted.php"); } As long as my username is in the table it says that I've voted today. Anyone know how to fix this? Link to comment https://forums.phpfreaks.com/topic/270563-mysql-once-every-24-hours/ Share on other sites More sharing options...
Pikachu2000 Posted November 11, 2012 Share Posted November 11, 2012 You're trying to directly compare two different formats; e.g. a TIMESTAMP field (YYYY-MM-DD hh:mm:ss) to a UNIX timestamp. $query = "SELECT COUNT(1) FROM table WHERE time > DATE_SUB( NOW(), INTERVAL 1 DAY ) AND uname = '$uname'"; $result = mysql_query($query); $array = mysql_fetch_row($result); if( $array[0] > 0 ) { // etc. Link to comment https://forums.phpfreaks.com/topic/270563-mysql-once-every-24-hours/#findComment-1391696 Share on other sites More sharing options...
fantity Posted November 11, 2012 Author Share Posted November 11, 2012 Thanks! Link to comment https://forums.phpfreaks.com/topic/270563-mysql-once-every-24-hours/#findComment-1391699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.