Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Finding rows where date was over 30 days ago or was not set
Old 07-21-2010, 10:03 PM Finding rows where date was over 30 days ago or was not set
Skilled Talker

Posts: 83
Trades: 0
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 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;

?>
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-21-2010, 10:20 PM Re: Finding rows where date was over 30 days ago or was not set
Average Talker

Posts: 16
Name: Filip Filipov
Location: Bulgaria
Trades: 0
A one way is:

$time = strtotime(
date("Y-m-d")) - 60*60*24*30;
$date =
date("Y-m-d", $time);
$drawquery = mysql_query("SELECT `id` FROM `users` WHERE `date` > '".$date."' ORDER BY rand() LIMIT 1");

__________________

Please login or register to view this content. Registration is FREE
- IP Address Lookup. Domain Lookup. Geolocation by IP or Doomain Name

Please login or register to view this content. Registration is FREE
- Check PageRank, Alexa Rank, Backlinks, Indexed Pages, ...
primecode is offline
Reply With Quote
View Public Profile Visit primecode's homepage!
 
Old 07-24-2010, 01:48 AM Re: Finding rows where date was over 30 days ago or was not set
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
select * from users where date > now() - interval 30 day or date = 0 order by rand limit 3
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Finding rows where date was over 30 days ago or was not set
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20781 seconds with 12 queries