【发布时间】:2016-05-05 02:10:48
【问题描述】:
我正在尝试使用 PHP 将来自具有 CS:GO 统计数据的 Steam 用户的数据插入 MySQL 数据库。我需要将 stats 数组中的 name 和 value 值插入到我将在 Android 应用程序中显示的 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
},
// ...
]
}
}
【问题讨论】:
-
请同时说明您的实际问题!
-
那个更好看?
-
您应该明确说明您遇到问题的部分。否则,这是一个非常广泛的问题。我还是试着回答了。