1

I have a value and the second one is the model part which is used for storing the data in JSON format. Here spam_management is the column in the table in that I have to store like [{delete:30}]. 30 is the value taken from the selected option. How can I do that?

public function update_selectedspmlds()
{
  $value = $this->input->post("value");
  $this->approval_model->update_selectedspmlds($value);
}

public function update_selectedspmlds($value)
{   
  $myJson = '{
    "delete": [{
      "lastName": '.$value.'
    }]
  }'; 
  $this->db->insert('pm1cti_details', ['spam_management' => $myJson]); 
}
1
  • Do it like this json_encode($myJson) Commented Mar 19, 2020 at 9:58

1 Answer 1

1

In order to create a JSON and store like [{delete:30}]. You need to save the value in a nested array and create a JSON by json_encode before saving it to the DB.

public function update_selectedspmlds($value) {   
  $myArray = array(
               array(
                'delete' => 30
              )
            );
  $myJson = json_encode($myJson);
  $this->db->insert('pm1cti_details', ['spam_management' => $myJson]); 
}
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.