php - how to update mysql table from Serialised json? -


i have serialised nestable, don't know how write php code update database wordpress:

$data = '[{"id":1},{"id":2,"children":[{"id":3},{"id":4},{"id":5,"children":[{"id":6},{"id":7},{"id":8}]},{"id":9},{"id":10}]},{"id":11},{"id":12}]';  function extract_value($value,$order=0){         if(is_array($value)){             foreach($value $k => $v){                 echo "update vod_page_menu set ordering = '$order', parent_id = '$v' id = '$v'; <br/>";                 extract_value($v,$order+1);             }                }     } $json = json_decode($data,true); extract_value($json); 

you need first decode json, can use in php:

$data = json_decode($data, true); foreach ($data $id => $value) { ... } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -