在我的优惠券栏中,数据如此显示为500,501,502 OK ..
优惠券栏中有3个值,所以我在每个优惠券价值的数据库中插入3行。
我需要插入coupondate也是每个循环运行中的增量顺序...假设上面循环运行3次然后3 coupondate插入coupondate列。
多数民众赞成......这就是为什么我在那里使用循环......
请帮助解决我的问题。 我需要在数据库中插入每个日期而不是最后一个。
$coupon = $_POST['coupon'];
$arr = explode(",", $coupon);
$min = min($arr);
$max = max($arr);
$startingdate = $_POST['startingdate'];
for ($i = 1; $i <= $max; $i++)
{
$coupondate = date("d-m-Y", strtotime(date("d-m-Y", strtotime($startingdate)) . " +" . $i . "month"));
for ($i = $min; $i <= $max; $i++)
{
$insertrow = $database->insertRow("INSERT INTO book_issue (coupondate,coupon) VALUES (:coupondate,:coupon)", array(':coupondate'=>$coupondate,':coupon'=>$i));
}
}
答案 0 :(得分:0)
检查以下代码,错过了递增的月份值
for($i = $min; $i <= $max; $i++) {
$dates[] = $coupon . " - " . date("d-m-Y", strtotime($startingdate . " +" . $i . " MONTHS -1 DAYS"));
}
echo "<pre>";
print_r($dates); //out put you required
echo "</pre>";
答案 1 :(得分:0)
OOP方式:
$startingdate = '26-02-2015';
$date = new DateTime($startingdate);
$diff = new DateInterval('P1M');
for($i = 0; $i < 5; $i++) {
$date->add($diff);
print_r($date);
}
答案 2 :(得分:0)
试试这个:
$startingdate = '26-02-2015';
$min = 0;
$max = 2;
for($i = $min; $i <= $max; $i++) {
$dates[] = date("d-m-Y", strtotime($startingdate . " +" . ($i+1) . " MONTHS"));
}
var_dump($dates);
答案 3 :(得分:0)
$coupon = $_POST['coupon'];
$arr = explode(",", $coupon);
$min = min($arr);
$max = max($arr);
$startingdate = date("d-m-Y", strtotime($_POST['startingdate']));
for ($i = 1 ; $i <= count($arr) ; $i++) {
$count = 1;
for ($ii = $min; $ii <= $max; $ii++) {
$coupondate = date("d-m-Y", strtotime(date("d-m-Y", strtotime($startingdate)) . " +" . $count . " month"));
$count++;
$insertrow = $database->insertRow("INSERT INTO book_issue (coupondate) VALUES (:coupondate)", array(':coupondate'=>$coupondate));
}
}