Insert JSON values in MYSQL using PHP -
i've json string:
$json = '{ "bigprodlist": { "prods": [ { "code": 55, "name": "comix book", "link": "weblink" }, { "code": 85, "name": "it book", "link": "weblink" }, { "code": 95, "name": "manga book", "link": "weblink" } } }'; i'd print every single entry on webpage using php , save these entries on mysql db. in db there "code", "name" , "link" field..
this i've tried without luck (to print stuff on page):
$obj = json_decode($json,true); echo ($obj["bigprodlist"]["prods"][0]["name"]); thank much help
first, prepare json missing end bracket makes json decoding fail (add ] after prods info ), expand echo statement foreach loops info printed. simple illustration on right track:
foreach ($obj["bigprodlist"]["prods"] $p): echo "<div>"; foreach ($p $name=>$value): echo "<span>".$name.": ".$value."</span>"; endforeach; echo "</div>"; endforeach; you can utilize same loop procedure info db.
php mysql json
No comments:
Post a Comment