mardi 4 août 2015

how to update or add a value to an existing json array using PHP forms?

I have a json array stored as a field in a database table. Now I want to use add, edit and delete functions on them. The following code modifies the entire 'conditional_elements_dependencies' array.

  • edit.php:

        $dependent = $_POST['dependent'];
        $term =$_POST['term'];
        $dependee = $_POST['dependee'];
        $json=get_option('conditional_elements_dependencies'); // here I use syntax as specified in Omeka
        if (!$json) { $json="null"; }
        $data = json_decode($json, 1);
        $newdata = array('0'=>$dependent, '1' => $term, '2'=>$dependee);
        $data[] = $newdata;
        $json= json_encode($data);
    
    

But I need to know how to add or delete the specific data items such as dependee, term or dependent and not the entire json array.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire