0
暈,我有一個問題,在PHP中循環日期和時間。我有開始日期,結束日期,開始時間和結束時間的初始值。 我想循環20131201
直到20131210
與時間從0540
直到0600
。在選定的日期期間的循環日期和時間
我運行我的代碼,但它只是在20131201
循環。
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0540', '0545', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0545', '0550', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0550', '0555', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0555', '0600', 'IDR', '4','', 'royal', '0')
我希望它環路,並有導致這樣的:
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0540', '0545', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0545', '0550', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0550', '0555', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131201', '20131210', '0555', '0600', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131202', '20131210', '0540', '0545', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131202', '20131210', '0545', '0550', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131202', '20131210', '0550', '0555', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131202', '20131210', '0555', '0600', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131203', '20131210', '0540', '0545', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131203', '20131210', '0545', '0550', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131203', '20131210', '0550', '0555', 'IDR', '4','', 'royal', '0')
INSERT INTO golf_list VALUES ('', 'others', '', '20131203', '20131210', '0555', '0600', 'IDR', '4','', 'royal', '0')
...等等......直到10個步驟...
這是我的代碼:
$start_date = "20131201";
$end_date = "20131210";
$start_hour = "05";
$start_min = "40";
$end_hour = "06";
$end_min = "00";
//$end_time = $end_hour."".$end_minute;
//$players = $_POST['players'];
/*
$price = $_POST['price'];
$price_standard = $_POST['price_standard'];
$price_extra = $_POST['price_extra'];
*/
$price_type = 4;
$details = "";
$start = new DateTime("$start_hour$start_min");
$end = new DateTime("$end_hour$end_min");
for($i = $start_date; $i <= $end_date; $i++) {
while($start < $end) {
$start_time = $start->format('Hi');
$start->modify('+5 minute');
$end_time = $start->format('Hi');
$query1 = "INSERT INTO golf_list (golf_name, golf_type, location, start_date, end_date, start_time,
end_time, currency, price_type, details, gate, status)
VALUES ('', 'others', '', '$i', '$end_date', '$start_time',
'$end_time', 'IDR', '$price_type','$details', 'royal', '0')";
echo "$query1<br/>";
}
}
任何解決方案?非常感謝您
只要複製/粘貼此代碼在您的一個,和你將好去... – Joem
好的非常感謝你,只是不同的一些微小你的答案。我現在可以解決,我的答案也一樣:D –