I am trying to update a json value in mysql. But I notice It delete de Old value in the row.
$image = $wpdb->get_var($wpdb->prepare("SELECT id FROM users WHERE ext = $user_id"));
$where = array('custo' => $image);
$dataOld = $wpdb->get_var($wpdb->prepare("SELECT custom FROM users1 WHERE ext1 = $where"));
$dataOld = json_decode($dataOld, true);
$dataOld["2"]["value"] = "four";
$dataOld = json_encode($dataOld);
$data = array('customFields' => $dataOld);
$wpdb->update($wpdb->prefix . 'kings', $data, $where);
I have a json like this in sql:
{"1":{"label":"empo","value":""},"2":{"label":"Comp","value":"A"}}
Instead of update "value" it prints
{"2":{"value":"four"}}
I am trying to get this:
{"1":{"label":"empo","value":""},"2":{"label":"Comp","value":"four"}}
Update:
$image = $wpdb->get_var($wpdb->prepare("SELECT id FROM users WHERE ext = $user_id"));
$where = array('custo' => $image);
$dataOld = $wpdb->get_var($wpdb->prepare("SELECT custom FROM users1 WHERE ext1 = (SELECT id FROM users WHERE ext = $user_id)"));
$dataOld = json_decode($dataOld, true);
$dataOld["2"]["value"] = "four";
$dataOld = json_encode($dataOld);
$data = array('customFields' => $dataOld);
$wpdb->update($wpdb->prefix . 'kings', $data, $where);