Welcome Guest, Not a member yet? Register   Sign In
Store multiple "identical" arrays in a session - confused about variable/dynamic variables
#2

[eluser]bretticus[/eluser]
Can't really wrap my head around why you mention variable variables. Smile

I think what you possibly meant is arrays inside arrays. Just build your add_parts array by inserting part meta data arrays inside your container array. You can use the part number as the associative array key of your container array elements. For example, if your controller method were called register:

Code:
function register()
{
    $this->load->library(array('session','form_validation'));
    $this->load->helper(array('form', 'url'));
                
    // form validation rules

    if ($this->form_validation->run() !== FALSE)
    {
        //get $addparts from previous post
        
        $add_parts = $this->session->userdata('add_parts');
        
        if ( $add_parts === FALSE )
            $add_parts = array(); // initialize container array.            
        
        //part number becomes associative array key within container array.
        $addparts[$this->input->post('form_removed_part_number', TRUE)] = array(
            'form_description' => $this->input->post('form_description', TRUE),
            'form_part_failure_date' => $this->input->post('form_part_failure_date', TRUE),
            'form_work_order' => $this->input->post('form_work_order', TRUE)
        );

        // add it back to session
        $this->session->set_userdata('add_parts', $add_parts);
        
        // do your logic about form completion and database insertion
    }
}


Messages In This Thread
Store multiple "identical" arrays in a session - confused about variable/dynamic variables - by El Forum - 08-19-2010, 08:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB