Php 使用+;从forloop开始1个月

Php 使用+;从forloop开始1个月,php,mysql,pdo,Php,Mysql,Pdo,我的表格中的数据如下所示 我需要根据收据更新优惠券和coupondate…. input data from form like below. receipt = 700 coupon = 501,502,503,504,505,506 coupondate = 28-02-2015 但在更新代码运行后,会产生如下输出 receipt coupon coupondate 700 501 27-03-2015 700

我的表格中的数据如下所示

我需要根据收据更新优惠券和coupondate….

input data from form like below.

receipt      =  700
coupon       =  501,502,503,504,505,506
coupondate   =  28-02-2015
但在更新代码运行后,会产生如下输出

receipt    coupon  coupondate
 700        501    27-03-2015
 700        502    27-04-2015
 700        503    27-05-2015
 700        504    27-06-2015
 700        505    27-07-2015
 700        506    27-08-2015
我的for循环在更新代码中不工作…plz帮助生成正确的输出

下面是我的更新代码

但insert查询中的相同代码运行良好…但inh update它在所有行中产生相同的输出

请帮忙

receipt    coupon  coupondate
 700        501     27-03-2015
 700        501     27-03-2015
 700        501     27-03-2015
 700        501     27-03-2015
 700        501     27-03-2015
 700        501     27-03-2015
if(isset($\u GET['edit']))
{
$receipt_no=$_GET['edit'];
$优惠券=$_POST['优惠券'];
$arr=爆炸(“,”,$优惠券);
$min=min($arr);
$max=max($arr);
$startingdate=日期(“d-m-Y”,标准时间($_POST['startingdate']);
对于($i=1;$i$coupondate,
“:优惠券”=>j美元,
“:startingdate”=>$startingdate,
“:startingdate”=>$startingdate,
“:收据编号”=>$收据编号
)
);        
}   
}
}

您的SQL查询会显示
WHERE receipt\u no=:receipt\u no
,因此它会始终将相同的数据放在所有具有该receipt\u no的行中。您需要准确地指定应该更新的行

顺便说一下,您有两个嵌套的for循环,而您只需要一个for循环

 if(isset ($_GET['edit']))
 {
    $receipt_no = $_GET['edit'];
    $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 ($j = $min; $j <= $max; $j++)
        {

            $coupondate = date("d-m-Y", 
                               strtotime(date("d-m-Y", 
                                 strtotime($startingdate)) . 
                                 " +" . $count . " month - 1days"));
            $count++;                   
            $updaterow = $database->updateRow(
                         "UPDATE receipt_entry 
                          SET 
                          coupondate=:coupondate,
                          coupon=:coupon,
                          startingdate=:startingdate 
                          WHERE receipt_no = :receipt_no",
                                array(':coupondate'=>$coupondate,
                                      ':coupon'=>$j,
                                      ':startingdate'=>$startingdate,
                                      ':startingdate'=>$startingdate,
                                      ':receipt_no'=>$receipt_no
                                     )
                          );        
        }   

    }
}