Update Json string that stored on DB - php

I have DB table that one of his Column contain a JSON string like this:
{"freet1":"\u05d2'\u05dc\u05d0\u05e8\u05d8\u05d4 \u05de\u05d5\u05d3\u05d9\u05e2\u05d9\u05df - \u05de\u05d5\u05d3\u05d9\u05e2\u05d9\u05df - \u05ea\u05e4\u05e8\u05d9\u05d8 \u05de\u05e9\u05dc\u05d5\u05d7\u05d9\u05dd - Ice Cream | Tinder","freet2":"5% \u05d4\u05e0\u05d7\u05d4","freet3":"\u05dc\u05de\u05d6\u05de\u05d9\u05e0\u05d9\u05dd \u05d3\u05e8\u05da \u05d4\u05d0\u05ea\u05e8","freet6":"\u05d4\u05d4\u05d6\u05de\u05e0\u05d4 \u05e9\u05dc\u05d9","freet4":"\u05d0\u05d9\u05df \u05d0\u05e4\u05e9\u05e8\u05d5\u05ea \u05dc\u05e9\u05e2\u05e8\u05da \u05d0\u05ea \u05d4\u05d4\u05d6\u05de\u05e0\u05d4 \u05de\u05db\u05d9\u05d5\u05d5\u05df \u05e9\u05d4\u05de\u05d5\u05e6\u05e8\u05d9\u05dd \u05e9\u05e7\u05d9\u05dc\u05d9\u05dd. \u05de\u05d9\u05e0\u05d9\u05de\u05d5\u05dd \u05de\u05e9\u05dc\u05d5\u05d7 45 \u05e9\"\u05d7","0":{"menu":"\u05d2\u05dc\u05d9\u05d3\u05d5\u05ea \u05e9\u05de\u05e0\u05ea","currentmenufile":"142525634133.JPG","data":[{"product":"\u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05de\u05e0\u05d8\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056679\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056679\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05d1\u05dc\u05d2\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056687\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056687\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05dc\u05d1\u05df","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056695\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056695\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05e7\u05d9\u05e0\u05d3\u05e8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056702\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056702\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05ea\u05e4\u05d5\u05d6","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056727\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056727\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e8\u05d9\u05d1\u05ea \u05d7\u05dc\u05d1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056815\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056815\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05dc\u05d5\u05d8\u05d5\u05e1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056823\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056823\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e7\u05e4\u05d5\u05e6'\u05d9\u05e0\u05d5","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056830\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056830\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d5\u05d9\u05e1\u05e7\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056944\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056944\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d5\u05e0\u05d9\u05dc \u05e6\u05e8\u05e4\u05ea\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056953\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056953\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e2\u05d5\u05d2\u05d9\u05d5\u05ea \u05d0\u05d5\u05e8\u05d0\u05d5","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425056962\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425056962\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05de\u05e7\u05d5\u05e4\u05dc\u05ea","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425057129\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425057129\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d5\u05e0\u05d9\u05dc \u05e7\u05dc\u05d9\u05e7","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425057136\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425057136\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e4\u05e0\u05d9\u05e0\u05ea \u05d9\u05e2\u05e8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425057143\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425057143\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d8\u05d5\u05d5\u05d9\u05e7\u05e1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425057472\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425057472\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e2\u05d5\u05d2\u05ea \u05d2\u05d1\u05d9\u05e0\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425057480\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425057480\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05ea\u05d5\u05ea \u05d1\u05e9\u05de\u05e0\u05ea","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425057487\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425057487\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e4\u05e8\u05e8\u05d5 \u05e8\u05d5\u05e9\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425058752\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425058752\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e7\u05e8\u05de\u05dc \u05de\u05dc\u05d5\u05d7","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425058759\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425058759\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d8\u05d5\u05e4\u05d9\u05e4\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425058768\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425058768\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d1\u05d0\u05d5\u05e0\u05d8\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425060944\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425060944\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e4\u05d9\u05e1\u05d8\u05d5\u05e7","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425060952\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425060952\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d5\u05e4\u05dc \u05de\u05d9\u05d9\u05e4\u05dc","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425060960\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425060960\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e0\u05d5\u05d8\u05dc\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425063548\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425063548\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05dc\u05d5\u05d0\u05e7\u05e8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425063559\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425063559\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d7\u05dc\u05d1\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425063567\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425063567\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e7\u05e8\u05dd \u05e9\u05e0\u05d9\u05d8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425256001\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425256001\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d1\u05e0\u05e0\u05d4 \u05e4\u05e7\u05d0\u05df","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410592\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410592\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e1\u05e0\u05d9\u05e7\u05e8\u05e1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425256019\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425256019\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d0\u05dc\u05e4\u05d7\u05d5\u05e8\u05e1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410136\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410136\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d8\u05d9\u05e8\u05de\u05d9\u05e1\u05d5","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410144\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410144\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05de\u05d2\u05e0\u05d5\u05dd","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410156\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410156\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e8\u05e4\u05d0\u05dc\u05d5","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410168\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410168\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d8\u05e2\u05de\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410185\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410185\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05de\u05d9\u05dc\u05e7\u05d9","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410193\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410193\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d9\u05d5\u05d2\u05d5\u05e8\u05d8 \u05d5\u05e4\u05d9\u05e8\u05d5\u05ea \u05d9\u05e2\u05e8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410202\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410202\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"}],"menufile":"142525634133.JPG"},"1":{"menu":"\u05d2\u05dc\u05d9\u05d3\u05d5\u05ea \u05e1\u05d5\u05e8\u05d1\u05d4","currentmenufile":"142532108933.JPG","data":[{"product":"\u05dc\u05d9\u05de\u05d5\u05df","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410247\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410247\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05dc\u05d9\u05de\u05d5\u05e0\u05e2\u05e0\u05e2","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410247\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410247\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05ea\u05d5\u05ea \u05e9\u05d3\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410255\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410255\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e4\u05e1\u05d9\u05e4\u05dc\u05d5\u05e8\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410270\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410270\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05de\u05e0\u05d2\u05d5","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410270\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410270\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05ea\u05e4\u05d5\u05d7 \u05d9\u05e8\u05d5\u05e7","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410270\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410270\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e4\u05d9\u05e8\u05d5\u05ea \u05d9\u05e2\u05e8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410278\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410278\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05de\u05e8\u05d9\u05e8","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410284\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410284\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e7\u05d5\u05e7\u05d5\u05e1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410290\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410290\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d3\u05d9\u05d0\u05d8 \u05e4\u05d9\u05e8\u05d5\u05ea","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"u","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410297\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410297\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"}],"menufile":"142532108933.JPG"},"2":{"menu":"\u05d2\u05dc\u05d9\u05d3\u05d5\u05ea \u05e1\u05d5\u05d9\u05d4","currentmenufile":"142532142833.JPG","data":[{"product":"\u05d1\u05d5\u05d8\u05e0\u05d9\u05dd","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410304\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410304\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d7\u05dc\u05d1\u05d4","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410310\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410310\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e4\u05d9\u05e1\u05d8\u05d5\u05e7","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410321\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410321\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05dc\u05d5\u05d8\u05d5\u05e1","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410316\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410316\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d0\u05d2\u05d5\u05d6\u05d9 \u05dc\u05d5\u05d6","desc":"","price":"84","pgraysmall":"\u05dc\u05e7"\u05d2","pgreen":"","unit":"k","pnew":"u","psale":"u","pactive":"y","currentfile":"1425410327\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425410327\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"}],"menufile":"142532142833.JPG"},"3":{"menu":"\u05e7\u05d9\u05e0\u05d5\u05d7\u05d9\u05dd","currentmenufile":"142564673833.JPG","data":[{"product":"\u05e7\u05e8\u05e4 \u05e6\u05e8\u05e4\u05ea\u05d9","desc":"","price":"18","pgraysmall":"\u05dc\u05d9\u05d7'","pgreen":"","unit":"u","pnew":"u","psale":"u","pactive":"y","currentfile":"1425646773\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425646773\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e7\u05e8\u05e4 + \u05d2\u05dc\u05d9\u05d3\u05d4 + \u05e7\u05e6\u05e4\u05ea","desc":"","price":"30","pgraysmall":"\u05dc\u05d9\u05d7'","pgreen":"","unit":"u","pnew":"u","psale":"u","pactive":"y","currentfile":"1425646783\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425646783\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05d5\u05d5\u05e4\u05dc \u05d1\u05dc\u05d2\u05d9","desc":"+ 2 \u05db\u05d3\u05d5\u05e8\u05d9\u05dd + \u05e7\u05e6\u05e4\u05ea \u05d5\u05e1\u05d9\u05e8\u05d5\u05e3","price":"49","pgraysmall":"\u05dc\u05d9\u05d7'","pgreen":"","unit":"u","pnew":"u","psale":"u","pactive":"y","currentfile":"1425646790\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425646790\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"},{"product":"\u05e1\u05d5\u05e4\u05dc\u05d4 \u05e9\u05d5\u05e7\u05d5\u05dc\u05d3 \u05d7\u05dd","desc":"+ \u05db\u05d3\u05d5\u05e8 \u05d2\u05dc\u05d9\u05d3\u05d4 + \u05e7\u05e6\u05e4\u05ea \u05d5\u05e1\u05d9\u05e8\u05d5\u05e3","price":"38","pgraysmall":"\u05dc\u05d9\u05d7'","pgreen":"","unit":"u","pnew":"u","psale":"u","pactive":"y","currentfile":"1425796952\u05ea\u05e4\u05e8\u05d9\u05d8.JPG","file":"1425796952\u05ea\u05e4\u05e8\u05d9\u05d8.JPG"}],"menufile":"142564673833.JPG"}}
Is it possible to update only 1 "product" in this way? Because if I have more then 1,000 products the update is very slow (update all the string)
Better way then get the string by SQL Select the decode,change spesific values and then update the full string?
Thanks!

To update part of a JSON string stored in MySQL, you'll indeed need to retrieve, decode to an array/object, edit, encode as JSON, and store. It's time-consuming.
I'd recommend a change to your table schema. Not sure how it's set up right now, but instead of having one table with all of your info, you could have one table just for Products, another for Orders, another for Customers, etc.
So in your Products table, you'd have one row per product:
ID | NAME | DESCRIPTION | PRICE
00123| jacket | gray wool jacket | $4.99
Then in another table when you need to reference this product, you simply need to use the ID value. You can update the table rows for products much easier than editing their JSON.

Regarding your first question, you cannot update only one product. There should be a row for each product, sounds like a terrible database design. It could make some sense if it was an static page but if you want to update or delete products it's gonna be really costly.
EDIT: Obviously when I said "you cannot update only one product" I meant to say that you must decode JSON string, modify the resulting array and encode it again to update a single product". It would have been more correct to say "you cannot update only one product without having to update the whole JSON array".

Related

How to store variable length arrays in a database

I'm looking for a way to save data based off a set of rows in another table, but I don't know how to set up the field. Think something similar to using the results of a mysql group_concat as the field. The data is based off the unique combination of rows, rather than one row or field.
What I need to be able to do is:
Store the array itself in the database
Store associated data about the array
Retreive the array
The ability to lookup data about the array using the data in the array
Some options I've thought about:
Saving as an ordered set concatenated into a string.
Saving the serialized array (serialized using php's serialize function).
Saving the set as a hashed string using a reversible hash.
None of these options seem correct so I came here hoping someone has a better answer.
Background:
Supposed I have the following tables:
users {id, other unimportant fields}
products {id, other unimportant fields}
shipments {id, user_id, product_id, date, other unimportant fields}
I want to create a new table called assigned_products where the assigned product is based off of the unique combination of products they've received in the past. So assigned_products should look like:
assigned_products {set_of_products_received (array), product_id (data about the array)}
I don't know of a good way to store set_of_products_received in a database.
Example use:
Suppose I have 100 users who got product A, 100 users who got product B, and 100 users who got products A and B. Suppose then I wanted to give product B to everyone who got product A, product A to everyone who got product B, and product C to everyone who got product A and B. The assigned products table should look like:
+--------------------------+------------+
| set_of_products_received | product_id |
+--------------------------+------------+
| A | B |
| B | A |
| A, B | C |
+--------------------------+------------+
I'm just looking for a better way of storing set_of_products_received
Reading this over I realize it's a bit hard to understand, but I don't really know the appropriate terms to describe this issue (probably why I'm having trouble finding solutions). I'll be happy to clarify if anyone has any questions.

update record, or delete and re-insert if the user edits their cart before processing the order

I have a table named orders_products which hold all the products associated with each individual orders. Now, if the customer decides to edit the quantity, the attributes, or simply just remove a product, what would be the easiest way to handle this change in the database?
orders_products
id | quantity | fk_products_id | attributes | price | fk_orders_nr
fk_products_id refers to the actual product id in our products table
attributes is a comma sepparated string with id's refering to our attributes table (attributes can be the angle, lenght, diameter etc. for each product. As in 45 degres, left angeled, 20 cm in length, 43mm in diameter).
fk_orders_nr is the actual order the product belongs to.
Since I have a class that handles this part on the client side. Would it be easier to just DELETE all associated products, based on the order id (fk_orders_nr), and just re-insert and updated the whole set based on what's stored in the class?
Or is there a neat way to handle this directly in MySQL?
I've looked a bit into on duplicate key update, and ignore, but they doesn't seem to fit my needs..
I need to check to see if the actual product id exists, then decide to insert new, or update existing (it could be both the quantity, and/or optional attributes), also the product might be removed if not in the list from the class anymore.
When writing this question. I think deleting the whole set, and reinsert it, might be the easiest way.
This database looks badly designed. Firstly I assume by fk_products_id you mean product_id. You do not need to specify that a column is a foreign key in its name.
Secondly, I would advise you to keep all columns atomic, as in, no multi-values. The attributes column keeping a comma-separated list will give you headaches in the future and it also breaks the FIRST normal form (the most basic one).
Thirdly, you don't need (although it could sometimes be useful) an id as a primary key in your junction table. You can just use a compound primary key from your fk_products_id and fk_orders_nr keys.
When writing this question. I think deleting the whole set, and
reinsert it, might be the easiest way.
Yes, that is the way it's usually done.
But I insist you ignore everything about the current problem you're having and redesign your database from scratch, putting special attention into normalization. These are basic database design standards and they exist for a reason. Hopefully you won't learn about the reason when it's too late.

Have an array in a SQL field. How to display it systematically?

I have a field in a data feed coming in with some values separated by commas. For one record, the values are:
A06,C05,C06,C15,C18,C19,C21,C22,E05,E22,G11,J02,J07,L04,L07,M01,M05,N03,N07,N10,N11,N12,N18,N19,N20,N24,O02,O03,O04,O06,O09,O14,O15,O16,O20,O21,O31,Q01,Q04,Q08,R07,S08,T08,T12,T23,T32,U01,U03,U04,U06,U13,W09,W11,W16,W19,W30,W45,X02,X03,X12,Z07
I have a separate table with some descriptions as to what each code means. When I query the main table and get this field name as a value, I can use explode to get it into an array and use a foreach loop to output each value.
The problem is, I want to display the description stored in another table. What's the proper way of iterating through this to display these values in a list?
As an example, C21 means "Gated Community."
You can use FIND_IN_SET() function for that.
Example you have record like this
Orders Table
------------------------------------
OrderID | attachedCompanyIDs
------------------------------------
1 1,2,3 -- comma separated values
2 2,4
and
Company Table
--------------------------------------
CompanyID | name
--------------------------------------
1 Company 1
2 Another Company
3 StackOverflow
4 Nothing
Using the function
SELECT name
FROM orders, company
WHERE orderID = 1 AND FIND_IN_SET(companyID, attachedCompanyIDs)
will result
name
---------------
Company 1
Another Company
StackOverflow
As you have tagged codeigniter you could use the built in Active Record's method $this->db->where_in(); to get the description. For example consider the code below
$codes = array('A06', 'C05', 'C06');
$this->db->where_in('description', $codes);
// Produces: WHERE codes IN ('A06', 'C05', 'C06')
For more information about Active Records of Codeigniter refer Active Record Class
For more information on how mysql WHERE IN works refer Tutorial
Just for follow the books, the best way of doing this in SQL language is to use the relationship.
For understand this I recommend you read this simple paper http://net.tutsplus.com/tutorials/databases/sql-for-beginners-part-3-database-relationships/
and maybe this http://www.informit.com/articles/article.aspx?p=30875&seqNum=5 for SELECT the data, or search for yourself on the web, and I recommend you to try yourself the examples. SQL Relationship Is good and necessary for security and many others reasons.

How to store an array of an inventory in php/mysql?

The end user has an inventory such as:
dogs:0, cats:3, dragons:20 etc you get the point.
So for a 30 inventory string array, what is the best way to store the values in mysql
and then use them with php? do i need to use json for this? because i would like
to update for instance a user "buying" another dragon and update the record occasionally.
Just use a seperate table for this, which has a reference to the object (if an object table exist), the player it belongs to and the number of items. No need to store a json string in a table.
Table Objects
-----------------
id | Object name
Table Inventory
----------------------------------
id | player_id | object_id | count
Store in a table containing Id, Name, Quantity.
You need JSON to communicate with php without reloading the page (AJAX), but it can be generated dynamically.

Writing specific values to a database X times?

To begin with, i should clarify the title, so you really understand what I'm trying to do.
I'm working on a shopping-cart-ish script, but it's a little different because all products (almost always) will be purchased each time. Therefore i believe it's best to list all of the items up with a table, and then let the customer choose the amount of each product they want.
It'd look something like this:
-- Name ------------------------- Amount --
-- A random product ------------- 15 ------
-- Another random product ------- 2 -------
-- And a third one --- ---------- 19 ------
-- ------------------------------ ---------
-- ------------------------------ SUBMIT --
The problem is, I'm not sure how to write it into the database. Or more specific, i don't know how to submit the data in a way that i get all of the chosen products, as well as the amount of each one into an array. I might add more products to the database later, so i can't hardcode it in.
I can't post two values in one input, which is too bad. If i could do that i could post the ID and the amount as two different values.
Any ideas how to do this?
When you create your input fields, use an array for the name, with the product id as the key.
For example (where $product_id is the ID of the product that the amount corresponds to):
<input type="text" name="amounts[<?=$product_id?>]">
Then in PHP, after the form is posted, $_POST['amounts'] will be an array, where the keys are the product IDs, and the values are the actual amounts. You do not need to do anything special for this to happen; by default, PHP will recognize that GET/POST data that contains []s should be made into an array.
Then you can just iterate over this array to update the database:
foreach ($_POST['amounts'] as $product_id => $amount)
{
if (!empty($amount)) // was a value given for this amount?
{
// build your insert query here
}
}
concatenate the productID and the qty with a pipe "|" so it would be
productId=14
Qty= 3
inserted value= 14|3
then after your db fetch, you can explode the data by the "|" and have part1=14 and part2=3

Categories