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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

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

Post by Smudly »

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:

Code: Select all

<?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;

?>
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: Finding rows where date was over 30 days ago or was not

Post by Gargoyle »

Code: Select all

SELECT * FROM table WHERE date<NOW()-2592000;
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Finding rows where date was over 30 days ago or was not

Post by John Cartwright »

Duplicate. Locked.
Locked