【发布时间】:2012-10-31 08:08:58
【问题描述】:
可能重复:
Print Y-m-d list of business dates between two dates from MySQL using PHP
我是这种 PHP 编程的新手,所以请耐心等待。
我希望用户能够发布两个日期,一个开始日期和一个结束日期,然后根据这些日期计算营业日期(不包括周六和周日)并将其插入到MySQL
例如,如果我有这个表格...
<form action='update.php' method='post'>
<input type='text' name='start_date'>
<input type='text' name='end_date'>
<input type='submit' name='submit'>
</form>
update.php
if(isset($_POST['submit'])) {
$start_date = $_POST['start_date']; //Let's say this is 2012-10-01
$send_date = $_POST['end_date']; //Let's say this is 2012-10-10
}
现在我想遍历日期并创建一个 MySQL 查询,它会像这样运行:
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-01');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-02');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-03');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-04');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-05');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-08');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-09');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-10');
我知道这可能不是一个好的解决方案,但这正是我需要的。
如何创建循环?
【问题讨论】:
-
+1 解释清楚
-
我不建议这样做,这不是标准的数据库设计。它将提供大量数据重复