SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Get array values ​​from html code in PHP

    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 to change the html and php code to get the desired result?

    My html code is as:
    Code:
        <form action="#" method="post">
    
        	<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="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="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="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="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="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="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="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="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 Code:
        <?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('hoV', $DateArray); This is for CodeIgniter
            
    }
        
    ?>

  2. #2
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please help me


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •