以迭代方式插入到db

I want to insert to my database payment table that should be done in this way. The payment table that I have includes both group_id and member_id as a foreign key related to the table groups and member respectively. What I want to do is once I hit the button "Pay" it should insert for each and every member_id as a row in the payment table. Here is my code.. In my controller I have

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

And in my model which is the Member_model I've included in the controller..

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

Please help me out. Thank you.

Now I've solved the problem. In my controller there I have got the array value from the model...

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

Also on my previous model paymember method there was a problem which its not returning any result so I've fixed that with this code....

        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;

}

Thank you for ur support!