Forum Moderators: coopster
$product_number = (time() / 60) % $number_of_products;
define an "origin point" which is some Monday midnight some time in the past.
define an "origin point" which is some Monday midnight some time in the past.
<?php
//set the beginning of the current cycle - originally 19 July 2010 but can reset
$cycle_start = mktime(0, 0, 0, 11, 01, 2010);
//get today's date
$todays_date = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
//86400 seconds = 1 day
$seconds_per_day = 86400;
//show at least the next two weeks (14 days) in the calendar
$min_calendar_duration = 14;
//today is how long after cycle start?
$days_into_cycle = ($todays_date - $cycle_start)/$seconds_per_day;
//round days into cycle in case daylight saving time shafts our calculations by returning a fraction!
$days_into_cycle = round($days_into_cycle);
//get all the link ids and put them in an array
while($link_row = mysql_fetch_array($all_links_result)){
$links_array[]= $link_row["id"];
}
//count the number of links for each section
$number_links = count($links_array);
//are there more links to display than the min calendar duration?
$max_calendar_duration = max($number_links, $min_calendar_duration);
//get complete range of calendar
$calendar_range = $days_into_cycle + $max_calendar_duration;
//assign each link to a date, starting from the beginning of the cycle
$daycount = 1;
while($daycount <= $calendar_range){
foreach($links_array as $key => $link_id){
$link_day = $cycle_start + ($daycount * $seconds_per_day);
$links_dates_array[$link_day]= $link_id;
$daycount++;
}
}
//get today's links from the array
$link_today = $links_dates_array[$todays_date];
//start from today
$daycount = $days_into_cycle;
while($daycount < $calendar_range){
//calculate the day
$calendar_day = $cycle_start + ($daycount * $seconds_per_day);
//get this day's links from the array
$link_today = $links_dates_array[$calendar_day];
//get this day's links info from the database
$link_today_info = getLink($link_today);
//put this day's info into an array to put in the view table
$links_table_row[] = array (
'link_date' => date("l d F Y",$calendar_day),
'link_id' => $slink_today_info["id"],
'link' => substr($link_today_info["link"], 0, 100),
'link_order' => $link_today_info["ordering"];
$daycount++;
}
?>