PHP Json array decode in php and inserting mysql -
this question has answer here:
- how extract data json php? 2 answers
"sci-6":{"quantity":11,"id":"sci-6","price":15,"name":"notebooks"}, "sci-7":{"quantity":1,"id":"sci-7","price":10,"name":"posters"}, "sci-8":{"quantity":2,"id":"sci-8","price":15,"name":"pen"}, "sci-9":{"quantity":4,"id":"sci-9","price":100,"name":"charger"}, "sci-10":{"quantity":1,"id":"sci-10","price":10.25,"name":"news paper"}
please me decode variables , insert values mysql using php
$data = '{"sci-6":{"quantity":11,"id":"sci-6","price":15,"name":"notebooks"},"sci-7":{"quantity":1,"id":"sci-7","price":10,"name":"posters"},"sci-8":{"quantity":2,"id":"sci-8","price":15,"name":"pen"},"sci-9":{"quantity":4,"id":"sci-9","price":100,"name":"charger"},"sci-10":{"quantity":1,"id":"sci-10","price":10.25,"name":"news paper"}}'; $json_data=json_decode($data); foreach($json_data $json_value) { mysql_query("insert yourtable (quantity, id, price, name) values ('".$json_value->quantity."','".$json_value->id."','".$json_value->price."','".$json_value->name."')"); }
Comments
Post a Comment