2013-07-16 98 views
1

我將使用保修日,月和年創建保修日期。一次輸入一條記錄時,此功能正常工作。但我必須爲同一表單中的不同項目輸入幾個保修天數。保修日期錯誤 - 拍攝日期

for($value = 0; $value < count(array_filter($part_name1)); $value++){    
    if(!empty($year1[$value])||!empty($month1[$value])||!empty($days1[$value])){ 
     $warranty_date = $this->purchase_date; 
     if(!empty($days1[$value])){ 
      $warranty = strtotime($this->warranty_date); 
      $warranty = strtotime("+".$this->days." day", $warranty); 
      $warranty = date('Y-m-d', $warranty); 
      $warranty_date = $warranty; 
     } 

     if(!empty($month1[$value])){ 
      $warranty  = strtotime($this->warranty_date); 
      $warranty  = strtotime("+".$this->month." month", $warranty); 
      $warranty  = date('Y-m-d', $warranty); 
      $warranty_date = $warranty; 
     } 

     if(!empty($this->year)){ 
      $warranty  = strtotime($this->warranty_date); 
      $warranty  = strtotime("+".$this->year." year", $warranty); 
      $warranty  = date('Y-m-d', $warranty); 
      $warranty_date = $warranty; 
     } 


    } 
} 

請幫我查找這段代碼的錯誤。

該功能基於購買日期。
當我輸入多條記錄時,第一個權證日期顯示爲1970-01-01,第二個記錄保修日期正確,其餘顯示爲1970-01-01

+0

發生了什麼事? –

+0

它顯示第一個記錄1970-01-01,第二個記錄正確日期和第三個第四個等等。顯示1970-01-01 – Dula

+0

你的數組是正確的嗎? –

回答

2
you missed last curly brace 

<?php 


for($value = 0; $value < count(array_filter($part_name1)); $value++){    
      if(!empty($year1[$value])||!empty($month1[$value])||!empty($days1[$value])){ 
       $warranty_date = $this->purchase_date; 
       if(!empty($days1[$value])){ 
        $warranty = strtotime($this->warranty_date); 
        $warranty = strtotime("+".$this->days." day", $warranty); 
        $warranty = date('Y-m-d', $warranty); 
        $warranty_date = $warranty; 
       } 

       if(!empty($month1[$value])){ 
        $warranty  = strtotime($this->warranty_date); 
        $warranty  = strtotime("+".$this->month." month", $warranty); 
        $warranty  = date('Y-m-d', $warranty); 
        $warranty_date = $warranty; 
       } 

       if(!empty($this->year)){ 
        $warranty  = strtotime($this->warranty_date); 
        $warranty  = strtotime("+".$this->year." year", $warranty); 
        $warranty  = date('Y-m-d', $warranty); 
        $warranty_date = $warranty; 
       } 


      } 
} // this one 

?> 
+0

這不是問題;他們只是在他們的問題中忘了括號。 – Daedalus