使用for循环的增量日期php代码在更新条件下不起作用


php code for increment date using for loop not working in update condition

表名-receipt_entry

我的表单中有两个文本框和一个日期选择器

用户输入

receipt      =  700
coupon       =  501,502,503,504,505,506
coupondate   =  28-02-2015

然后在数据库中插入6行,因为文本框中有6张优惠券,并且每个日期自动生成6张优惠券(+1个月)。

插入后运行数据在表中插入,如下面的

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

我的问题是插入查询中的每一项操作都很顺利。

但当我尝试更新相同的东西时,所有列都会正确更新。但优惠券和coupondate并没有按递增顺序更新。

我尝试使用收据号进行更新,因为这在数据库中是唯一的。

UPDATE之后在下面的表中运行数据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

以下是我的代码:

编辑链接

<a href="customer_entry.php?edit=<?php echo htmlspecialchars($row['receipt_no']); ?>" class="ico edit">Edit</a>

插入代码

<?php
    require_once('includes/config.php');    
    if(!isset($_SESSION['Auth']['id'])) 
        {
            header('Location: index.php');
            exit;
        }            
    $errors = array();      
    if(isset($_POST['save']))
    {
                $receipt_no = $_POST['receipt_no'];             
                $coupon = $_POST['coupon'];                     
                $arr = explode(",", $coupon);
                $min = min($arr);
                $max = max($arr);                  
                $errors = $database->receipt_exists($receipt_no);
                    if(!count($errors))
                     {                                              
                            $startingdate = date("d-m-Y", strtotime($_POST['startingdate']));
                            for ($i = 1 ; $i <= count($arr) ; $i++) 
                            {
                                $count = 1;
                                for ($i = $min; $i <= $max; $i++)
                                {       
                                $coupondate = date("d-m-Y", strtotime(date("d-m-Y", strtotime($startingdate)) . " +" . $count . " month - 1days"));
                                $count++;   
    $insertrow = $database->insertRow("INSERT INTO receipt_entry (coupondate,receipt_no,coupon,startingdate)                        
VALUES(:coupondate,:receipt_no,:coupon,:startingdate)",array(':coupondate'=>$coupondate,':receipt_no'=>$receipt_no,':coupon'=>$i,':startingdate'=>$startingdate));                  
                                }
                            }                       
                    $_SESSION['message'] = "Customer Created Successfully";                 
                    }    
        }               
?>

更新代码

<?php
        if(isset($_POST['update']))
        {           
                $receipt_no = $_GET['edit'];
                $receipt_no = $_POST['receipt_no'];                     
                $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 ($i = $min; $i <= $max; $i++)
                {       
                $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,receipt_no=:receipt_no,coupon=:coupon,startingdate=:startingdate WHERE receipt_no = :receipt_no",
array(':coupondate'=>$coupondate,':receipt_no'=>$receipt_no,':coupon'=>$i,':startingdate'=>$startingdate,':receipt_no'=>$receipt_no));
                }
            }   
        }                   
?>

检查嵌套循环控制器。。在第二个循环中使用不同的var,然后使用$i

for ($i = 1 ; $i <= count($arr) ; $i++) 
{
  //....
  for ($j = $min; $j <= $max; $j++)
  {
     //.. .....:coupon'=>$j...
  }
}