【发布时间】:2015-12-22 19:20:37
【问题描述】:
我想创建一个选择开始日期和结束日期然后插入数据库的函数。我想从 30/8 到 30/9 每 4 天将日期插入数据库...
例如:
table
row 1 = 30/8
row 2 = 3/9
row 3 = 7/9
row 4 = 11/9 ... and so on
我的 php:
<?php
$con = mysql_connect("localhost", "root", "root");
mysql_select_db("test", $con);
$start_date= "2015-08-30";
$end_date= "2015-09-30";
$insert = "INSERT INTO calendar(date)......";
if(mysql_query($insert,$con)) {
echo "<script> alert('Insert Successful'); </script>";
}
else {
echo "<script> alert('Insert Unsuccessful'); </script>";
}
while (strtotime($start_date) <= strtotime($end_date)) {
//echo "$start_date <br>";
$start_date = date ("Y-m-d", strtotime("+4 day", strtotime($start_date)));
}
【问题讨论】:
-
先构建数据,然后将其构建到单个 SQL 语句中。
标签: php mysql database while-loop do-while