以前にも同様の質問をしましたが、絞り込んで、新しい質問を開始したいと思います。
次のスクリプトは、To と From の日付を DB レコードに挿入します。隔週スキップのオプションを追加したい。以下は非常に近いですが、やりたくない最初の週をスキップします。COUNT 機能を使用して、Count の奇数レコードのみを使用して挿入する方法はありますか?
$week_day = date('w', $curr); # 0 - 6 to access the $week array
if ($week[$week_day]) { # skip if nothings in this day
$date = date('Y-m-d', $curr);
$sql->query("SELECT COUNT(schedule_id) FROM $pageDB WHERE doctor_id = $doc_id AND schedule_date = '$date'");
if (!$sql->result(0)) { # skip if this is already defined
$date = date('Y-m-d', strtotime("+1 week", $curr));
$sql->query("INSERT INTO $pageDB (schedule_date, time, doctor_id, location_id) VALUES ('$date', '".$week[$week_day]."', $doc_id, '".$location[$week_day]."')");
}
}