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?

Edited by fantity
Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.