タイムスタンプをキー(dateGMT)とするデータ記録を持ついくつかのテーブルを持つデータベースがあります。1 と 0 の配列を返す関数を作成しようとしています。データに 4 時間以上のギャップがある日は 0 です。
何らかの理由で私の機能が動作しません。0 でマークする必要がある日の数を検索するときに関連していると思います。間違いを犯した可能性のある場所を確認できる人はいますか?
また、これは何らかの理由であまり効率的ではないように感じます。元のタスクを解決する他の方法も大歓迎です!
前もって感謝します!
//create array with the dates from start of recordings to now
$period = iterator_to_array(new DatePeriod(new DateTime('2013-06-10'),new DateInterval('P1D'),new DateTime()));
$p2 = array();
$n = 0;
//the actual date is used as key for the number of the date
foreach($period as $p){
array_push($p2,date('Y-m-d',strtotime($p->format('Y-m-d'))));
//other way i 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 FROM `$table` ORDER BY `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 the other way i tried: $ret[$p[$d1]] = 1;
}
$d1 = $d2;
}
return $ret;
}