0

The data posted, including the multi select field is

Array ( [id] => 16 [pAttr] => Array ( [0] => Colour [1] => Size ) ) 

I am trying to insert an id with one attribute only and do it again in second row.

____________________
|  id  | attribute |
--------------------
|  16  |  Colour   |
|  16  |  Size     |

The controller method

public function add_config_product()
{
    $data['id'] = $this->input->post('id');
    $data['attribute'] = $this->input->post('pAttr');

    /*$data = array(

        'id' => $this->input->post('id'),
        'attribute' => $this->input->post('pAttr')
    );*/

    //print_r($data);
    $this->inventory_model->add_config_product($data);
}

Model

public function add_config_product($data)
{
    $this->db->insert('product_attr_value', $data);
}

2 Answers 2

1

Try this:

Controller:

public function add_config_product()
{
    $data['id'] = $this->input->post('id');
    foreach ($this->input->post('pAttr') as $attribute):
        $data['attribute'] = $attribute;
        $this->inventory_model->add_config_product($data);
    endforeach;
}

This will loop through the pAttr input array and add values in each rows.

Sign up to request clarification or add additional context in comments.

Comments

0

If you pass an array of values to a function in model to insert, then you can use the following type :

public function add_config_product($data)
{
   $this->db->insert_batch('product_attr_value',$data);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.