2016-09-08 10 views
0

この方法で行う必要があるデータベースの支払いテーブルに挿入したいと思います。 私が持っている支払いテーブルには、テーブルグループとメンバーにそれぞれ関連する外部キーとしてgroup_idとmember_idの両方が含まれています。 私がしたいことは、一度、 "pay"ボタンを押すと、各member_idに支払いテーブルの行として挿入する必要があります。 はここ反復的にdbに挿入

function paymember(){ 
$data= array(); 
$this->db->where('group_id',$this->input->post('group_id')); 
$memberid = $this->db->get('member'); 
if ($memberid->num_rows() > 0) { 
     foreach ($memberid->result_array() as $row){ 
       $data[] = $row; 
      } 
} 
} 

私を助けてください..私は

public function create_action() 
{ 
    $this->_rules(); 

    if ($this->form_validation->run() == FALSE) { 
     $this->create(); 
    } else { 
     $this->load->model('Member_model'); 
     $memberid = $this->Member_model->paymember(); 
     foreach ($memberid->result_array() as $id){ 
       $memberid[] = $id; 
     $data = array(
    'group_id' => $this->input->post('group_id',TRUE), 
    'member_id' => $memberid, 
    'paid_by' => $this->input->post('paid_by',TRUE), 
    'from_date' => $this->input->post('from_date',TRUE), 
    'to_date' => $this->input->post('to_date',TRUE), 
    'amount' => $this->input->post('amount',TRUE), 
    'reference_number' => $this->input->post('reference_number',TRUE), 
    //'last_updated_by' => $this->input->post('last_updated_by',TRUE), 
    //'last_update_time' => $this->input->post('last_update_time',TRUE), 
    ); 
     } 

     $this->Payment_model->insert($data); 
     $this->session->set_flashdata('message', 'Record Created  Successfully!'); 
     redirect(site_url('payment')); 
    } 
} 

を持っていると私は、コントローラに含まれてきたMember_modelである私のモデルに私のコード..私のコントローラで です。ありがとうございました。

+0

'paymember()'は何も返されないようです。あなたのコードはすべてそこにありますか?また、 'member'テーブルから来るフィールドは何ですか? – DFriend

答えて

0

今問題を解決しました。そこに私のコントローラで 私は私の以前のモデルpaymember方法で、私はこのコードであることを修正しましたので、そのは、任意の結果を返さない問題があった。また...モデルから

  public function create_action() 
{ 
    $this->_rules(); 

    if ($this->form_validation->run() == FALSE) { 
     $this->create(); 
    } else { 
    $this->load->model('Member_model'); 
    $memberid = $this->Member_model->paymember(); 
     if (count($memberid)) { 
      foreach ($memberid as $id) { 

      $data = array(
     'group_id' => $this->input->post('group_id',TRUE), 
     'member_id' => $id, 
     'paid_by' => $this->input->post('paid_by',TRUE), 
     'from_date' => $this->input->post('from_date',TRUE), 
     'to_date' => $this->input->post('to_date',TRUE), 
     'amount' => $this->input->post('amount',TRUE), 
     'reference_number' => $this->input->post('reference_number',TRUE), 
     'last_updated_by' => $this->session->userdata('username'), 
     //'last_update_time' => $this->input->post('last_update_time',TRUE), 
     ); 
      $this->Payment_model->insert($data); 
      echo $data; 
     } 
    } 
     $this->session->set_flashdata('message', 'Record Created Successfully!'); 
     redirect(site_url('payment')); 
    } 
} 

を配列値を持っています....

 function paymember(){ 
$data= array(); 
$this->db->where('group_id',$this->input->post('group_id')); 
$query = $this->db->get('member'); 
    if ($query->num_rows() > 0) { 
     foreach ($query->result_array() as $row){ 
       $data[] = $row['member_id']; 
      } 
    } 
    $query->free_result(); 
    return $data; 

}

ウル支援ありがとうございます!

関連する問題