Re: Random pick

From: Date: Tue, 15 Dec 2009 02:17:28 +0000
Subject: Re: Random pick
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-46693@lists.php.net to get a copy of this message
On Monday 14 December 2009 21:02:37 Chris wrote: > David McGlone wrote: > > Hi everyone, > > > > I've been lurking in the shadows on the list for quite some time and now > > I'm in need of a little info or advise. > > > > I'm looking for a way to grab a record out of a database on a certain day > > each month and I'm wondering if this can be accomplished with just a > > mysql query or would I need to use PHP also? > > A mysql query would do it but you'd use something to talk to mysql and > process the results (whether it's php, perl, python, ruby etc depends on > your other requirements). > What I'm trying to do is to have a record picked from the database at random on the 1st of every month and display it on the page. Here is some code I have been working with: $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)"; $result = @mysql_query($query); if (!$result){ $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1"; $result = @mysql_query($query); while ($row = mysql_fetch_array($result)){ echo "$row[poochName] "; echo "$row[Birthdate]"; } } I suspect this code isn't going to work, because I think on the 1st day of the month it's going to choke. What do you think? -- Blessings David M. I have been driven to my knees many times by the overwhelming conviction that I had nowhere else to go.

« previous php.db (#46693) next »