@svidgenApr 30.2010 — #So, are you looking to have these displayed in sequence then? Or, at the start of a new week, does the first page-view need to trigger a rand() call to pick a record for the week?
@svidgenApr 30.2010 — #The simple version is like so:
[code=php]// populate this however you need/want. // each record is a joke. $jokes = array();
// grab the week-of-year. $week = (int)date('W');
// if you wish to adjust this based on day-of-week, do that here. // for instance, if we want the rollover on wednesday ... we might do: if ((int)date('w') >= 3) { $week++; }
// grab the joke. $todays_joke = $jokes[$week];[/code]
@porsche21authorApr 30.2010 — #This is what I have but it doesn't give me a joke. Could you explain a little more what is happening with the week & date?
[code=php] // populate this however you need/want. // each record is a joke. $jokes = array();
// if you wish to adjust this based on day-of-week, do that here. // for instance, if we want the rollover on wednesday ... we might do: if ((int)date('w') >= 3) { $week++; }
// grab the joke. $todays_joke = $jokes[$week]; echo $todays_joke;
@svidgenApr 30.2010 — #Yeah, you won't see anything with that code as is, b/c date('W') should return 17, whereas your array has a max index of 6 (7 entries); So ... I guess I should have mentioned, to start mid-year, you'll need to offset the week--probably after adjusting for day-of-week:
[code=php]$week -= 17;[/code]
... in full:
[code=php]// populate this however you need/want. // each record is a joke. $jokes = array();
// if you wish to adjust this based on day-of-week, do that here. // for instance, if we want the rollover on wednesday ... we might do: if ((int)date('w') >= 3) { $week++; }
// suppose we started 2 weeks ago ... $week -= 15;
// grab the joke. $todays_joke = $jokes[$week]; echo $todays_joke; [/code]
@svidgenApr 30.2010 — #[CODE]Could you explain a little more what is happening with the week & date?[/CODE]
date(str) returns a formatted date. W returns the week-of-year. w returns the day of week, 0 to 6. And again, test for off-by-one errors before putting this into production ?