Jump to content

Mysql Once Every 24 Hours


fantity

Recommended Posts

I am making a toplist for a game and users can vote their favorite one up every 24 hours. This is the mysql table:

 

Capture.PNG

 

Here is an example entry:

Capture2.PNG

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.