I'm looking to make a php script to update the mysql every hour from a json file.
the api is that
http://backpack.tf/api/IGetMarketPrices/v1/?key=51f7eb704bd7b8231900000c&appid=730&format=json
How i can copy this things from json and put them in the mysql?
I mean something like that
"AK-47 | Aquamarine Revenge (Battle-Scarred)": {
"last_updated": 1436569230,
"quantity": 34,
"value": 2268
},
"AK-47 | Aquamarine Revenge (Factory New)": {
"last_updated": 1436569230,
"quantity": 21,
"value": 9386
},
"AK-47 | Aquamarine Revenge (Field-Tested)": {
"last_updated": 1436569230,
"quantity": 55,
"value": 4968
},
"AK-47 | Aquamarine Revenge (Minimal Wear)": {
"last_updated": 1436569230,
"quantity": 40,
"value": 6018
},
"AK-47 | Aquamarine Revenge (Well-Worn)": {
"last_updated": 1436569230,
"quantity": 40,
"value": 3597
},
"AK-47 | Black Laminate (Battle-Scarred)": {
"last_updated": 1436569230,
"quantity": 50,
"value": 345
},
"AK-47 | Black Laminate (Factory New)": {
"last_updated": 1436569230,
"quantity": 8,
"value": 8593
},
"AK-47 | Black Laminate (Field-Tested)": {
"last_updated": 1436569230,
"quantity": 141,
"value": 308
},
I want this to go in the mysql like that
This is what I've got so far:
<?php
$json = file_get_contents('http://backpack.tf/api/IGetMarketPrices/v1/?key=51f7eb704bd7b8231900000c&appid=730&format=json');
$obj = json_decode($json,true);
//Database Connection
require_once 'db.php';
/* insert data into DB */
foreach($obj as $item) {
mysql_query("INSERT INTO `cyberst_CSGO`.`items` ( cost, lastupdate)
VALUES ('".$item['value']."'', '".$item['last_updated']."')");
}
//database connection close
mysql_close($con);
//}
?>