2010-12-19 15 views
0

私はユーザーサインアップフォームを持っています。クライアントの有効期限を作成する関数を挿入する必要があります。ドロップダウンの選択に応じて1年または2Codeigniterユーザーのサインアップ日付に年を追加する方法

ユーザー作成時に登録日に年の値を追加するにはどうすればよいですか?ここで

は、新しいユーザーのための私のコントローラである

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; 
} 

です! PHPののstrtotime()関数など

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

答えて

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

見て、あなたはこのようなオプションを使用することができ、セットアップあなたのデータ配列を持っている方法で:

$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の値をテストし、その値に基づいて年数を追加することができます。

0

おかげ