Something wierd with time() and curdate()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is something wierd going on over here...

I have a date field, datum, in mysql that I cast to a timestamp and check against time().
If the datum value is more than one day old the table finds a new random row and sets the datum field to CURDATE().
Now, this has worked for two years now, but today the script suddenly finds a new random row each time the script is run...
I've notice this just after 11 pm today.
As I can see from some debugging time() allways returns a higher value than the timestamp + 86400...
Have I missed something in this script for the last couple of years or is there a bug somewhere? Could it have something to do with the fact that we turned the time back one hour last night?

This is the code btw:

function bibelvers($link_id, $color = "white") {
 $myBible = new Bible($link_id, "FB");
 $myBible->set_delimiters("span","p","bibelversnum","text");
 $vers_nr = "";
 $vers_txt = "";
 $reset = false;
 $q = "SELECT vers,textkod,UNIX_TIMESTAMP(datum) as datum FROM dagensvers WHERE visad = 'NU'";
 $result = mysql_query($q, $link_id);
 if (mysql_affected_rows($link_id) == 1) {
  $v = mysql_fetch_object($result);
  if (time() > ($v->datum + ONEDAY)) {
   mysql_free_result($result);
   $q = "SELECT vers,textkod FROM dagensvers WHERE visad = 'NEJ'";
   $result = mysql_query($q, $link_id);
   $rows = mysql_affected_rows($link_id)-1;
   if ($rows >= 0) {
    mysql_data_seek($result, rand(0,$rows));
    $v = mysql_fetch_object($result);
    $q = "UPDATE dagensvers SET visad = 'JA' WHERE visad = 'NU'";
    mysql_query($q, $link_id);
    $q = "UPDATE dagensvers SET datum = CURDATE(), visad = 'NU' WHERE textkod = '".$v->textkod."'";
    mysql_query($q, $link_id);
   }
   else { $reset = true; }   
  }
 }
 else { $reset = true; }
 if ($reset) {
  $q = "UPDATE dagensvers SET visad = 'NEJ' WHERE visad = 'JA'";
  mysql_query($q, $link_id);
  $q = "SELECT vers,textkod FROM dagensvers WHERE visad = 'NEJ'";
  $result = mysql_query($q, $link_id);
  $rows = mysql_affected_rows($link_id)-1;
  mysql_data_seek($result, rand(0,$rows));
  $v = mysql_fetch_object($result);
  $q = "UPDATE dagensvers SET visad = 'NEJ' WHERE visad = 'NU'";
  mysql_query($q, $link_id);
  $q = "UPDATE dagensvers SET datum = CURDATE(), visad = 'NU' WHERE textkod = '".$v->textkod."'";
  mysql_query($q, $link_id);
 }
 $vers_nr = $v->vers;
 $vers_txt = $v->textkod;
 $myBible->str_vers_format($vers_txt, false, false);
 $str = "<div class='rubb' style='width:300px;'>\n".
  "\t&nbsp;DAGENS BIBELVERS | ".$vers_nr."\n".
  "\t<div class='brod_s' id='".$color."' style='height:65px; overflow:auto;'>\n".
  "\t\t<div style='width:275px; margin:0px; padding:0px;'>".
  $vers_txt.
  "\t\t</div>\n".
  "\t</div>\n".
  "</div>\n";
 return $str;
} 

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux