I've (attempted!) to create a script that which is supposed to produce a 'default' record on a table for every day of the year starting from YYYY-01-01.
I'm sure I've made the script more complicated than it needs to be but I was having quite a few problems working out the correct way to add 1 to the date being processed on every loop. Anyway, it did almost seem to be working ok!
The problem I'm getting is that the script works quite happily to a point and is creating a record for each day. It then reaches a certain record, in the most recent test 31st October although I don't think it's related to that particular day, and from then on it creates repeated records for that day until the end of the loop processing i.e. I've got a seperate record for every day until the 31st Oct, then it's creating bundles of other records for the 31st Oct instead of moving on to 1st Nov and so on. Hopefully my explanation makes sense!
Anyway, I'm pretty stumped so any advice anyone can offer would be greatly appreciated.
Here's the code I'm using. As I say, I'm sure I've made it more complicated than it needs to be but it's the best I could come up with at the time ! :
include('config.php');
include('functions.php');
//Connect to database using details from 'config.php'
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
//Initialise the working date - first day of year
$processdate = strtotime("2004-01-00");
$convertdate = date("Y-m-d", $processdate);
//Check if year is leap year
$leap_split = explode('-',$convertdate);
$isleapyear = IsLeapYr($leap_split[0]);
if ($isleapyear ==1) {
$numdays = 366;
} else {
$numdays = 365;
}
//Loop for 365/366 days to create full years worth of "normal hours' entries
for ($i = 0; $i <= $numdays; $i++)
{
$processdate += 86400; // (add 1 day)
$processdate = date("Y-m-d", $processdate);
//split date currently processed into seperate year, month and day
$split_date = explode('-',$processdate);
$processdate = strtotime($processdate);
//create 'normal hours' record on database
$sql = "INSERT INTO " . DB_TABLE_PREFIX . "mssgs SET uid=1, m=$split_date[1], d=$split_date[2], y=$split_date[0], ";
$sql .= "start_time='09:00:00', end_time='17:00:00', title='Normal Hours', text='Normal Hours'";
mysql_query($sql) or die(mysql_error());
}