I want values in html code that is checked and values input text inserted batch in database mysql , As follows:

in 0-1 or ... , 0 is same checkboxDA[**0**][].
Row is same rows database table.

Row 0-1: a,aaa,AA
Row 0-2: b,BB
Row 0-3: c,CC

Row 1-1: aa,AA
Row 1-2: b,bbb,BB
Row 1-3: cc,ccc,CC

Row 2-1: aa,aaa,AA
Row 2-2: b,bbb,BB
Row 2-3: c,cc,CC

Here is demo of my code: http://codepad.viper-7.com/siDC84

How should I change to get the desired result?

My html code is as:

<form action="#" method="post">
<input type="text" name="IdRelInto[]" value="111" style="display: none">
    <input type="text" name="IdRelTo[]" value="1111" style="display: none">
    <input type="checkbox" name="checkboxDA[0][]" value="a" checked>a
    <input type="checkbox" name="checkboxDA[0][]" value="aa" >aa
    <input type="checkbox" name="checkboxDA[0][]" value="aaa" checked>aaa
    <input type="text" name="prts[]" value="AA">

    <input type="text" name="IdRelTo[]" value="1111" style="display: none">
    <input type="checkbox" name="checkboxDA[0][]" value="b" checked>b
    <input type="checkbox" name="checkboxDA[0][]" value="bb" >bb
    <input type="checkbox" name="checkboxDA[0][]" value="bbb" >bbb
    <input type="text" name="prts[]" value="BB">

    <input type="text" name="IdRelTo[]" value="1111" style="display: none">
    <input type="checkbox" name="checkboxDA[0][]" value="c" checked>c
    <input type="checkbox" name="checkboxDA[0][]" value="cc" >cc
    <input type="checkbox" name="checkboxDA[0][]" value="ccc" >ccc
    <input type="text" name="prts[]" value="CC">

<input type="text" name="IdRelInto[]" value="222" style="display: none" style="display: none">
    <input type="text" name="IdRelTo[]" value="2222" style="display: none">
    <input type="checkbox" name="checkboxDA[1][]" value="a" >a
    <input type="checkbox" name="checkboxDA[1][]" value="aa" checked>aa
    <input type="checkbox" name="checkboxDA[1][]" value="aaa" >aaa
    <input type="text" name="prts[]" value="AA">

    <input type="text" name="IdRelTo[]" value="2222" style="display: none">
    <input type="checkbox" name="checkboxDA[1][]" value="b" checked>b
    <input type="checkbox" name="checkboxDA[1][]" value="bb" >bb
    <input type="checkbox" name="checkboxDA[1][]" value="bbb" checked>bbb
    <input type="text" name="prts[]" value="BB">

    <input type="text" name="IdRelTo[]" value="2222" style="display: none">
    <input type="checkbox" name="checkboxDA[1][]" value="c" >c
    <input type="checkbox" name="checkboxDA[1][]" value="cc" checked>cc
    <input type="checkbox" name="checkboxDA[1][]" value="ccc" checked>ccc
    <input type="text" name="prts[]" value="CC">

<input type="text" name="IdRelInto[]" value="333" style="display: none">

    <input type="text" name="IdRelTo[]" value="3333" style="display: none">
    <input type="checkbox" name="checkboxDA[2][]" value="a" >a
    <input type="checkbox" name="checkboxDA[2][]" value="aa" checked>aa
    <input type="checkbox" name="checkboxDA[2][]" value="aaa" checked>aaa
    <input type="text" name="prts[]" value="AA">

    <input type="text" name="IdRelTo[]" value="3333" style="display: none"> 
    <input type="checkbox" name="checkboxDA[2][]" value="b" checked>b
    <input type="checkbox" name="checkboxDA[2][]" value="bb" >bb
    <input type="checkbox" name="checkboxDA[2][]" value="bbb" checked>bbb
    <input type="text" name="prts[]" value="BB">

    <input type="text" name="IdRelTo[]" value="3333" style="display: none"> 
    <input type="checkbox" name="checkboxDA[2][]" value="c" checked>c
    <input type="checkbox" name="checkboxDA[2][]" value="cc" checked>cc
    <input type="checkbox" name="checkboxDA[2][]" value="ccc" >ccc
    <input type="text" name="prts[]" value="CC">

<input type="submit" value="Submit">
</form>

My php code is as:

<?php
    if($_POST){
        foreach ($_POST['IdRelInto'] as $idx1 => $value1) {
            foreach ($_POST['IdRelTo'] as $idx => $value) {
                $DateArray[] = array(
                    'checkboxDA'  => $_POST['checkboxDA'][$idx],
                    'prts'        => $_POST['prts'][$idx],
                    'IdRelInto'   => $_POST['IdRelInto'][$idx],
                    'IdRelTo'     => $_POST['IdRelTo'][$idx]
                    );
            };
        };
                echo '<pre>';
                print_r($DateArray);
    //$this->db->insert_batch('hoPV', $DateArray); This is for CodeIgniter
    }
?>
share|improve this question

60% accept rate
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.