Jump to content

Finding rows where date was over 30 days ago or was not set


Recommended Posts

I'm creating a daily drawing system. The users have a chance to win every day. Once a user wins, they will not be able to win again for 30 days. I need to select all rows inside my mysql database that have dates over 30 days ago, or are still set as default (0000-00-00). How can I do something like this?

 

I've tried a few different ways but none seem to work. Once these rows are selected, it randomly chooses 3 winners, and sets their new dates to the current date.

 

Current code:

 

<?php

include_once('../inc/connect.php');

$date = date("Y-m-d");

$drawquery = mysql_query("SELECT id FROM users ORDER BY rand() LIMIT 1");
$row = mysql_fetch_assoc($drawquery);

$wondaily = $row['wondaily'];

$userid = $row['id'];
echo $userid;

?>

Haven't tested, but maybe (or similar):

 

$drawquery = mysql_query("SELECT id FROM users ORDER BY rand() WHERE (`date_column` INTERVAL + 30 DAYS) > CURDATE() AND  DATE(`date_column`) <> '0000-00-00' LIMIT 1");

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.