2010-12-19 121 views
0

我有一個用戶註冊表單,我需要插入一個函數來創建客戶端到期日期。 1或2年取決於下拉選擇。Codeigniter如何添加一年到用戶的註冊日期

如何在創建用戶時將年份值添加到註冊日期?

這是我的一個新的用戶

function new_member() 
{ 
    $data = array(
     'Last_Name' => $this->input->post('Last_Name'), 
     'First_Name' => $this->input->post('First_Name'), 
     'Salutation' => $this->input->post('Salutation'), 
     'Address' => $this->input->post('Address'), 
     'City' => $this->input->post('City'), 
     'Province' => $this->input->post('Province'), 
     'Postal' => $this->input->post('Postal'), 
     'Email' => $this->input->post('Email'), 
     'Dial_Up' => $this->input->post('Dial_Up'), 
     'Phone_1' => $this->input->post('Phone_1'), 
     'Phone_2' => $this->input->post('Phone_2'), 
     'Language' => $this->input->post('Language'), 
     'Membership_Cat' => $this->input->post('Membership_Cat'), 
     'Special_Member_Cat' => $this->input->post('Special_Member_Cat'), 
     'Membership_Status' => $this->input->post('Membership_Status'), 
     'Date_DNR' => $this->input->post('Date_DNR'), 
     'Gift_Membership' => $this->input->post('Gift_Membership'), 
     'Gift_Giver' => $this->input->post('Gift_Giver'), 
     'Membership_Length' => $this->input->post('Membership_Length'), 
     'Dues_Paid' => $this->input->post('Dues_Paid'), 
     'Donation' => $this->input->post('Donation'), 
     'Payment_Method' => $this->input->post('Payment_Method'), 
     'Date_Received' => $this->input->post('Date_Received'), 
     'Date_Input' => $this->input->post('Date_Input'), 
     'Membership_Date' => $this->input->post('Membership_Date'), 
     'Renew_Letter_1' => $this->input->post('Renew_Letter_1'), 
     'Renew_Letter_2' => $this->input->post('Renew_Letter_2'), 
     'Renew_Letter_3' => $this->input->post('Renew_Letter_3'), 
     'Date_Letter_Sent' => $this->input->post('Date_Letter_Sent'), 
     'Vol_FA' => $this->input->post('Vol_FA'), 
     'Vol_TEL' => $this->input->post('Vol_TEL'), 
     'Vol_CD' => $this->input->post('Vol_CD'), 
     'Vol_SCBA' => $this->input->post('Vol_SCBA'), 
     'Vol_MAIL' => $this->input->post('Vol_MAIL'), 
     'Vol_SML' => $this->input->post('Vol_SML'), 
     'Vol_BODCOM' => $this->input->post('Vol_BODCOM'), 
     'Vol_OTHER' => $this->input->post('Vol_OTHER'), 
     'Member_Since' => $this->input->post('Member_Since'), 
     'Notes' => $this->input->post('Notes'), 
     ); 

    $this->membership_model->add_record($data); 
    $this->load->view('index_view'); 
} 

控制器這是我的模型

function add_record($data) 
{ 
    $this->db->insert('Membership', $data); 
    return; 
} 

任何幫助表示讚賞!

感謝

回答

1

我接受了你的建議並查看了strtotime函數。由於我有2個會員資格,1和2年,我還需要在函數中提出一個變量。剛剛完成測試,這裏是

$Membership_Length = $this->input->post('Membership_Length'); 
     if($Membership_Length == "1") 
     { 
      $length = "+1 year"; 
     } 
     else 
     { 
      $length = "+2 years"; 
     } 

    $Expiry_Date1 = $this->input->post('Membership_Date'); 
    $Expiry_Date = strtotime($length , strtotime($Expiry_Date1)); 
    $Expiry_Date = date('Y-m-j', $Expiry_Date); 
    $date_expiry_array = array('Expiry_Date' => $Expiry_Date); 
    $data = array_merge($data, $date_expiry_array); 
0

看看PHP的strtotime()的功能,例如

$expiry = date('yy-mm-dd', strtotime('+1 year')); 
0

與已安裝的方式你的數據陣列可以使用這樣一個選項:

$date_received = $this->input->post('Date_Received'); 
$date_expiry = strtotime(date("Y-m-d", strtotime($date_received)). " +1 year"; 
$date_expiry_array = array('Date_Received'=>$date_expiry); 
$data = array_merge($data, $date_expiry_array); 

或如果您使用這種方法:

$date_received = $this->input->post('date_received'); 
$data['date_received'] = strtotime(date("Y-m-d", strtotime($date_received)). " +1 year 

「;

如果要測試1年或2年的過期期限,可以添加if語句以測試date_received的值,然後根據該值添加年數。