$createDate = mktime(0,0,0,10,28,date("Y"));
$selectedDate = date('d-m-Y', ($createDate));
$active = 0;
$sql = "UPDATE Session SET Active = ? WHERE SessionDate <= ?";
$update = $mysqli->prepare($sql);
$update->bind_param("is", $active, $selectedDate);
$update->execute();
I don’ think I have set the above code correctly as that I am running a CRON job where I have stated that every 28th October (today), it will set the “Active” field to 0.
Problem is that it is setting the active field to “0” for all the rows in my database, even if its after the 28th October this year.
Below is what is suppose to happed:
-
Now the current year is 2012 so when it becomes 28th October (which it is now), any exam which “SessionDate” is before this date should have an “Active” value of “0”, the other Exams remain having an “Active” value of “1”.
-
The CRON will then not do it’s job till next year when it is October 28th again, this time the year will obviously be 2013. The same rules apply any exam which “SessionDate” is before this date should have an “Active” value of “0”, the other Exams remain having an “Active” value of “1”.
-
The CRON will then not do it’s job till the following year when it is October 28th again, this time the year will obviously be 2014. The same rules apply any exam which “SessionDate” is before this date should have an “Active” value of “0”, the other Exams remain having an “Active” value of “1”.
And so on….
So how come all of my database rows are their “Active” fields set to 0 when the CRON is doing it’s bit?
The reason this did not work is because the date structure did not match the date structure from the database.
In my php script I got it as:
It should be like this: