find dates of data gaps from mysql db with php -


i have db few tables data recordings timestamps key (dategmt). trying create function returns array of 1 , 0, 0 every day there gap in data of 4 hours or more.

for reason function won't work, think related when searching number of day need mark 0. able see might have made mistake?

also, not feel efficient reason, other ways solve original task welcome!

thanks in advance!

//create array dates start of recordings $period = iterator_to_array(new dateperiod(new datetime('2013-06-10'),new dateinterval('p1d'),new datetime())); $p2 = array(); $n = 0; //the actual date used key number of date foreach($period $p){   array_push($p2,date('y-m-d',strtotime($p->format('y-m-d'))));   //other way tried: $p2[$p->format('y-m-d')]= $n; $n++; }  function makearr($table,$p) {   $con = mysql_connect("127.0.0.1", "user", "pass");   mysql_select_db("table",$con);    $ret = array_pad(array(),count($p),0);   $query = "select dategmt `$table` order `dategmt` asc";   $result = mysql_query($query);    $d1 = strtotime('2013-06-10');   $n = 0;   while ($row = mysql_fetch_assoc($result, mysql_assoc)){     $d2 = strtotime(implode("",$row));     if($d1+14400 > $d2){       $ret[array_search(date('y-m-d',$d1),$p)] = 1;       //part of other way tried: $ret[$p[$d1]] = 1;      }     $d1 = $d2;   }   return $ret; } 

there several ways find gaps using sql query, check post: method of finding gaps in time series data in mysql?


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -