0

Good evening. For learning purposes I am building a CRUD script with the possibility for drag and drop rows using ajax. While sending the data from the controller to the model, my model function is unable to treat the array so I am encountering a problem.

Controller function:

public function from_ajax() {
    $this->load->model('model');
    $ordem = $this->input->post('ordem');
    parse_str($ordem, $array_ordenado);
    var_dump($array_ordenado); //testing only
    $resultado = $this->model->reordem($array_ordenado);
    echo json_encode($resultado);           
}

var_dump on controller output:

array(1) { ["teste"]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "3" [2]=> string(1) "2" [3]=> string(1) "4" } }

Here is my model function:

public function reordem($data) {
    $this->db->select('page_order');
    $this->db->from('tbl_posts');
    return $this->db->update('tbl_posts', $data);
}

How would I treat this array dump on my model function so I can get the value I want (the ones inside "")?

I'm also getting this error: php/database error Thank you for your time!

1

1 Answer 1

1

You need to convert the array to a string

$array_ordenado['teste'] = implode(",", $array_ordenado['teste']);

The database doesn't support the array datatype. The code above would covert the field "teste"'s value from an array to a string with commas as delimiter.

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

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.