Auto Updating
Posted: Fri Feb 28, 2003 9:08 pm
Ok I've been working on this game for the past... well its been 8 months now.. its just me. and I'm starting work on the actual update page... but I can do that... what I'm having troubles with, is when do i update the site.
I have this script i'm working on, and it surpose to run the update.php file every 12 hours... now i have a time in the databse from which to go off of. but i cant seem to get anything to work.. i'm totally stumped..
what i need to do is compare the current time, with the time in the database.. if the current time is greater than the time in the database than run the update script... then set the new time equaling 12 more hours than the last time in the database...
but also have to take in the factor is someone hasnt visited the site in more than a day .. therefore more than 24 hours.. so i have to check how many times i have to run it as well.. then the new time has to be the number of times i ran the script * 12 (hours), and add that to the old time to get the new time...
does anyone get what i'm talking about... anyway heres the crappy code that I produced (and doesnt work)
that looks horrible.. if anyone can help me I'm desprite... thanks
I have this script i'm working on, and it surpose to run the update.php file every 12 hours... now i have a time in the databse from which to go off of. but i cant seem to get anything to work.. i'm totally stumped..
what i need to do is compare the current time, with the time in the database.. if the current time is greater than the time in the database than run the update script... then set the new time equaling 12 more hours than the last time in the database...
but also have to take in the factor is someone hasnt visited the site in more than a day .. therefore more than 24 hours.. so i have to check how many times i have to run it as well.. then the new time has to be the number of times i ran the script * 12 (hours), and add that to the old time to get the new time...
does anyone get what i'm talking about... anyway heres the crappy code that I produced (and doesnt work)
Code: Select all
$run = 0; // leave it at zero.. its how many times it should update
$updatetime = 12; // how often hourly.. so ever 12 hours it should update
// grabbing the time from the db ("z-H:i")
// note theres only 1 feild and 1 column in the database, and the columns called time
$up = mysql_fetch_array(mysql_query("SELECT * FROM dbz_update"));
$up2 = $upї0];
$da = explode("-", $up2);
$upday = $daї0];
$h = explode(":", $daї1]);
$uphour = $hї0];
$timezone = date("O"); // same time zone
if ($timezone == "-0500"){
$day = date("z"); // getting their time
$hour = date("H");
// if the hour is greater than the db hour
if ($hour > $uphour) {
// if its actually the next day or more
if ($day > $upday){
$diffhour = ($day - $upday) * 24;
$run = floor(@(($diffhour-$hour) / $updatetime));
// if its not the next day
} else {
$run = floor(@(($uphour-$hour) / $updatetime));
}
// if the hour is less than(it must be the next day) the db hour.
} else {
if ($day > $upday){
$diffhour = ($day - $upday) * 24;
$run = floor(@(($diffhour-$hour) / $updatetime));
}
}
// not in my time zone... so have to adjust
} else {
// find the diffrerence in the time zones
$newtimez = ($timezone - (-0500));
$day = date("z"); // getting their time
$hour = (date("H") - $newtimezone);
if ($hour > 24) {
$day++;
$hour -= 24;
}
// after that set the $day and $hour to my time zone(-0500)
// and the rest should fall in place
// if the hour is greater than the db hour
if ($hour > $uphour) {
// if its actually the next day or more
if ($day > $upday){
$diffhour = ($day - $upday) * 24;
$run = floor(@(($diffhour-$hour) / $updatetime));
// if its not the next day
} else {
$run = floor(@(($uphour-$hour) / $updatetime));
}
// if the hour is less than(it must be the next day) the db hour.
} else {
if ($day > $upday){
$diffhour = ($day - $upday) * 24;
$run = floor(@(($diffhour-$hour) / $updatetime));
}
}
}
// now set new date to update