Welcome Guest, Not a member yet? Register   Sign In
Batch updating Arrays
#1

I'm trying to batch update two records..

'studentextendID' is the primary key, so it's dynamic.. 'studentID' is static, What im trying to do is to update two records of the same 'studentID'

But instead, the output produces 6 arrays, the same exact number in a single array..

When it should produce 2 arrays only. and i put different values for each record, but one of these values goes to the two records instead.

Any advices?

My Controller:
PHP Code:
$studentextends $this->studentextend_m->get_order_by_studentextend(array('studentID' => $studentID));
                        $studentExtendArray = [];
                        if(customCompute($studentextends)) {

                            foreach($studentextends as $studentextend) {
                                $studentextendID $studentextend->studentextendID;
                                $post $this->input->post();
                                for($i=0$i count($post['subject']); $i++) {
                                    $studentExtendArray[] = array(
                                        'studentextendID' => $studentextendID,
                                        'studentID' => $studentID,
                                        'subject' => $post['subject'][$i],
                                        'subjectng' => $post['subjectng'][$i],
                                        'subjectlg' => $post['subjectlg'][$i],
                                        'subjectcre' => $post['subjectcre'][$i]
                                    );
                                
                                
}
                            }
                            $this->db->update_batch('studentextend'$studentExtendArray'studentextendID');
                        

Output:

PHP Code:
Array(
[
0] => Array
    (
        [studentextendID] => 1131
        
[studentID] => 306
        
[subject] => subject1
        
[subjectng] => A513
        
[subjectlg] => 113
        
[subjectcre] => 36513
    
)

[
1] => Array
    (
        [studentextendID] => 1131
        
[studentID] => 306
        
[subject] => subject2
        
[subjectng] => A514
        
[subjectlg] => 114
        
[subjectcre] => 36514
    
)

[
2] => Array
    (
        [studentextendID] => 1131
        
[studentID] => 306
        
[subject] => 
        [subjectng] => 
        [subjectlg] => 
        [subjectcre] => 
    )

[
3] => Array
    (
        [studentextendID] => 1132
        
[studentID] => 306
        
[subject] => subject1
        
[subjectng] => A513
        
[subjectlg] => 113
        
[subjectcre] => 36513
    
)

[
4] => Array
    (
        [studentextendID] => 1132
        
[studentID] => 306
        
[subject] => subject2
        
[subjectng] => A514
        
[subjectlg] => 114
        
[subjectcre] => 36514
    
)

[
5] => Array
    (
        [studentextendID] => 1132
        
[studentID] => 306
        
[subject] => 
        [subjectng] => 
        [subjectlg] => 
        [subjectcre] => 
    ) ) 

Expected Output:

PHP Code:
Array (
[
0] => Array
    (
        [studentextendID] => 1131
        
[studentID] => 306
        
[subject] => subject1
        
[subjectng] => A513
        
[subjectlg] => 113
        
[subjectcre] => 36513
    
)

[
1] => Array
    (
        [studentextendID] => 1132
        
[studentID] => 306
        
[subject] => subject2
        
[subjectng] => A514
        
[subjectlg] => 114
        
[subjectcre] => 36514
    

Reply




Theme © iAndrew 2016 - Forum software by © MyBB