Re: Random pick
| From: | Karl DeSaulniers | Date: | Sat, 19 Dec 2009 08:54:34 +0000 |
| Subject: | Re: Random pick | ||
| References: | 1 2 3 4 5 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46719@lists.php.net to get a copy of this message | ||
Dont know if you found anything, but I ran accross this in on of my other searches.
http://php.about.com/od/finishedphp1/p/day_redirect.htm
Karl
On Dec 18, 2009, at 10:10 AM, Philip Thompson wrote:
On Dec 15, 2009, at 6:02 PM, David McGlone wrote:Karl DeSaulniers Design Drumm http://designdrumm.comOn Monday 14 December 2009 21:44:24 Chris wrote:Could you not just create a mysql table that contains the month and a url to a file? <?php // image.php $currentMonth = date('n'); $sql = "SELECTChris wrote:Hmmm. This isn't exactly what I'm looking for. What I'm trying to do is get a new picture on the 1st of every month and display it for that whole month.David McGlone wrote:See http://php.net/date for date formats and what they return.On Monday 14 December 2009 21:02:37 Chris wrote:You can check the day of the month in php then do your other query: $today = date('j');David McGlone wrote: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]"; } }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).if ($today !== 1) { echo "Today isn't the first. No need to continue.\n"; exit; } .. random query etc here.image_locationFROMmonthly_imagesWHEREmonth= $currentMonth LIMIT 1"; $result = mysql_query($sql); list ($loc) = mysql_result ($result); header ("Content-type: image/png"); readfile ($loc); exit; ?> And then in your HTML: <img src="image.php" alt="MonthlyImage" title="Yay for me!" /> I just wrote that code here in the email, but it should get you going in the right direction. Hope that helps! ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php