我試圖從蒸汽用戶插入數據與CS:GO使用PHP數據到MySQL數據庫。我需要將stats
數組中的name
和value
數值插入MYSQL中,我將在Android應用程序中顯示該數組,但我不確定如何完成該操作。從蒸汽API存儲蒸汽遊戲數據到MySQL數據庫
代碼:
<?php
$con = new mysqli('mysql6.000webhost.com','a2689951_Cheesy','ansmh1997', 'a2689951_mSicx');
if (mysqli_connect_error()) {
echo mysqli_connect_error();
exit;
}
$stats = file_get_contents("http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=<key>&steamid=76561198050187807");
$json = json_decode($stats, true);
$stats = array();
foreach ($content['playerstats']['stats'] as $stat) {
$stats[$stat["name"]] = $stat["value"];
}
$insert = "INSERT INTO user (total_kills, total_deaths) VALUES (?, ?)";
$stmt = $con->prepare($insert);
$stmt->bind_param("ss", $total_kills, $total_deaths);
?>
API輸出示例:
{
"playerstats": {
"steamID": "76561198050187807",
"gameName": "ValveTestApp260",
"stats": [
{
"name": "total_kills",
"value": 35179
},
{
"name": "total_deaths",
"value": 30241
},
{
"name": "total_time_played",
"value": 2444377
},
// ...
]
}
}
請同時說明您的真正問題! –
這看起來更好? –
您應該明確指出您遇到問題的部分。否則,這是一個非常廣泛的問題。無論如何,我試圖回答它。 –