CodeIgniter Forums
Need help with Multi Dimensional Array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need help with Multi Dimensional Array (/showthread.php?tid=48463)



Need help with Multi Dimensional Array - El Forum - 01-17-2012

[eluser]vincej[/eluser]
Hi -

I keep the error "Undefined index" - here is the background:

I have a form with several check boxes all with the same name but with different values. For example check box 'publish_page' could have values 33, 64, 78 and so on. I also have on my form a check box 'delete_page' which also will have values. So I submit my form data as $_POST data to my controller. It arrives inside my controller as a multi dimensional array eg:

Array ( [publish_page] (array [0]=> 33 [1]=> 64 and so on

[delete_page] array [0] => 1 [1] => 53 and so on

)


I need to get these values into a DB table called 'pages' where I store those pages to be published and those to be deleted.

I have tried several approaches, none with success. My querie within my model is working. But it does not see the sub arrays, it only sees the top level array which of course it can not read.

So I have tried building in my controller a foreach which splits out the top array adn assigns the sub array values to $variables.


The 'undefined index' error is being reported on my controller. Looking at the page profile, I can see that the query is runnning but to no effect as the page id's are missing.

I'm new to CI and I am not having any success in extracting these subvariables. perhaps my approach is completely flawed !

As always I am Very Gratefull for All Your Help !! I hope one day I can 'give back' !

controller:

Code:
function accept_delete() {
foreach ($_POST as $key =>$value){
                $delete = $value['delete'];
  $accept = $value['accept'];
  }

if(isset($_POST['accept']))
        {
$this->MBlog->ApprovePage($_POST['accept']);
}
        if(isset($delete)){
$this->MBlog->DeletePage($delete);

        }


  }




Need help with Multi Dimensional Array - El Forum - 01-18-2012

[eluser]vincej[/eluser]
THANK YOU ! It worked a treat ... a couple of extra foreach statements to pull the sub arrays and it worked great !!