Welcome Guest, Not a member yet? Register   Sign In
Get array values ​​from html code in PHP
#1

[eluser]SaSa[/eluser]
I use CodeIgniter and 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.

Quote:Row 0-1: a,aaa,AA<br>
Row 0-2: b,BB<br>
Row 0-3: c,CC<br>

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

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

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:
Code:
&lt;form acti method="post"&gt;
    &lt;input type="text" name="IdRelInto[]" value="111"  none"&gt;
     &lt;input type="text" name="IdRelTo[]" value="1111"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[0][]" value="a" checked&gt;a
     &lt;input type="checkbox" name="checkboxDA[0][]" value="aa" &gt;aa
     &lt;input type="checkbox" name="checkboxDA[0][]" value="aaa" checked&gt;aaa
     &lt;input type="text" name="prts[]" value="AA"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="1111"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[0][]" value="b" checked&gt;b
     &lt;input type="checkbox" name="checkboxDA[0][]" value="bb" &gt;bb
     &lt;input type="checkbox" name="checkboxDA[0][]" value="bbb" &gt;bbb
     &lt;input type="text" name="prts[]" value="BB"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="1111"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[0][]" value="c" checked&gt;c
     &lt;input type="checkbox" name="checkboxDA[0][]" value="cc" &gt;cc
     &lt;input type="checkbox" name="checkboxDA[0][]" value="ccc" &gt;ccc
     &lt;input type="text" name="prts[]" value="CC"&gt;
    
    &lt;input type="text" name="IdRelInto[]" value="222"  none"  none"&gt;
     &lt;input type="text" name="IdRelTo[]" value="2222"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[1][]" value="a" &gt;a
     &lt;input type="checkbox" name="checkboxDA[1][]" value="aa" checked&gt;aa
     &lt;input type="checkbox" name="checkboxDA[1][]" value="aaa" &gt;aaa
     &lt;input type="text" name="prts[]" value="AA"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="2222"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[1][]" value="b" checked&gt;b
     &lt;input type="checkbox" name="checkboxDA[1][]" value="bb" &gt;bb
     &lt;input type="checkbox" name="checkboxDA[1][]" value="bbb" checked&gt;bbb
     &lt;input type="text" name="prts[]" value="BB"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="2222"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[1][]" value="c" &gt;c
     &lt;input type="checkbox" name="checkboxDA[1][]" value="cc" checked&gt;cc
     &lt;input type="checkbox" name="checkboxDA[1][]" value="ccc" checked&gt;ccc
     &lt;input type="text" name="prts[]" value="CC"&gt;
    
    &lt;input type="text" name="IdRelInto[]" value="333"  none"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="3333"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[2][]" value="a" &gt;a
     &lt;input type="checkbox" name="checkboxDA[2][]" value="aa" checked&gt;aa
     &lt;input type="checkbox" name="checkboxDA[2][]" value="aaa" checked&gt;aaa
     &lt;input type="text" name="prts[]" value="AA"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="3333"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[2][]" value="b" checked&gt;b
     &lt;input type="checkbox" name="checkboxDA[2][]" value="bb" &gt;bb
     &lt;input type="checkbox" name="checkboxDA[2][]" value="bbb" checked&gt;bbb
     &lt;input type="text" name="prts[]" value="BB"&gt;
    
     &lt;input type="text" name="IdRelTo[]" value="3333"  none"&gt;
     &lt;input type="checkbox" name="checkboxDA[2][]" value="c" checked&gt;c
     &lt;input type="checkbox" name="checkboxDA[2][]" value="cc" checked&gt;cc
     &lt;input type="checkbox" name="checkboxDA[2][]" value="ccc" &gt;ccc
     &lt;input type="text" name="prts[]" value="CC"&gt;
    
    &lt;input type="submit" value="Submit"&gt;
    &lt;/form&gt;

My php code is as:
Code:
&lt;?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('hotel_unitsPV', $dataPV); This is for CodeIgniter
     }
    ?&gt;
#2

[eluser]SaSa[/eluser]
Please help me




Theme © iAndrew 2016 - Forum software by © MyBB