i am using php to get the json values and have no problem looping though the data and echoing the SteamName, Level, Experience and more. However I do not know how to echo the steamid number 7656119801319... per proile.
json file:
{
"FURNACES": {},
"PROFILE": {
"76561198013191579": {
"SteamName": "Cayos",
"Level": 22,
"Experience": 1592,
"Agility": 22,
"Strength": 22,
"Intelligence": 22,
"StatsPoints": 66,
"SkillPoints": 2,
"Skills": {
"lumberjack": 20
},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"76561198113765447": {
"SteamName": "CaptainCheesy",
"Level": 31,
"Experience": 3576,
"Agility": 31,
"Strength": 70,
"Intelligence": 70,
"StatsPoints": 15,
"SkillPoints": 5,
"Skills": {
"miner": 8,
"lumberjack": 10,
"hunter": 8
},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"76561198141845337": {
"SteamName": "Carrot",
"Level": 3,
"Experience": 409,
"Agility": 3,
"Strength": 3,
"Intelligence": 3,
"StatsPoints": 9,
"SkillPoints": 3,
"Skills": {},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"76561198012539649": {
"SteamName": "Booglee",
"Level": 3,
"Experience": 110,
"Agility": 3,
"Strength": 3,
"Intelligence": 3,
"StatsPoints": 9,
"SkillPoints": 3,
"Skills": {},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
},
"333228975": {
"SteamName": "SYN Gaurd",
"Level": 0,
"Experience": 0,
"Agility": 0,
"Strength": 0,
"Intelligence": 0,
"StatsPoints": 0,
"SkillPoints": 0,
"Skills": {},
"Preferences": {
"ShowXPMessagePercent": 0.25,
"ShowCraftMessage": true,
"UseBlinkArrow": true,
"AutoToggleBlinkArrow": true
}
}
}
}
My PHP Code:
$url = 'C:\Users\plosey\Desktop\GameServers\Rust\steam\server_syn1\server\syn1\oxide\data\Hunt_Data.json'; //Url to the cars api
$content = file_get_contents($url);
$json = json_decode($content);
foreach($json->PROFILE as $user) {
echo $user->SteamName;
echo $user->NEED STEAM ID HERE; // This is the line that is not correct.
}
so in short i would need to not only echo the SteamName but the Steamid number from the same profile.
Instead of
foreach($json->PROFILE as $user) {
use
foreach ($json->PROFILE as $steamid => $user) {
Try below code to print id. $stremId will print your ID. You can replace it with any variable name.
$json = json_decode($json);
foreach($json->PROFILE as $streamId => $user) {
echo $user->SteamName;
echo $streamId;
}
try this
foreach($json->PROFILE as $key => $user) {
echo $key .' => '.$user->SteamName."<br/>";
}
Related
Hi i have 3 arrays in my JSON file
{
"Temperatures": [26.00, 26.50, 26.50, 0.00, 0.00, 20.00, 0.00, 0.00, 0.00],
"ThermoStatus": [0, 0, 0, -6, -6, -6, -3, -6, -6],
"FurnaceArray": [{
"Oven": {
"Thermo": [1, 4],
"SetPoint": 60.5
},
"Part": {
"Thermo": [2, 3],
"SetPoint": 60.5
},
"Outer": {
"Thermo": [5],
"SetPoint": 60.5
},
"TimerElapsed": 79,
"HeaterOutput": 0.600,
"ProgramPhase": 1,
"HeaterState": 3,
"OvenStatus": {
"DoorOpened": true,
"EmergencyPressed": false,
"ProgramDone": false
}
},
{
"Oven": {
"Thermo": [5, 6],
"SetPoint": 60.5
},
"Part": {
"Thermo": [7],
"SetPoint": 60.5
},
"Outer": {
"Thermo": [5],
"SetPoint": 60.5
},
"TimerElapsed": 79,
"HeaterOutput": 0.600,
"ProgramPhase": 1,
"HeaterState": 3,
"OvenStatus": {
"DoorOpened": true,
"EmergencyPressed": false,
"ProgramDone": false
}
}
]
}
I've combined the Oven Thermo and the Part Thermo. Like this.
$comTemperatures = array($json->FurnaceArray[0]->Oven->Thermo , $json->FurnaceArray[0]->Part->Thermo);
And now i want to use $comTemperatures as an index for Thermostatus. How can i show the temperatures which the index is given in $comTemperatures
i now have this
foreach ($comTemperatures as $value) {
if ($thermostatus[$value] == 0) {
echo $temperatures[$value];
}
}
but i get an error "illegal offset type" at the foreachloop.
Can someone help me
If I understand you correctly:
$jsonArray = json_decode($jsonString); //$jsonString is the JSON you shared
$thermostatus = $jsonArray->ThermoStatus;
$temperatures = $jsonArray->Temperatures;
//Merge two arrays into one instead of making one array of arrays
$comTemperatures = array_merge($json->FurnaceArray[0]->Oven->Thermo , $json->FurnaceArray[0]->Part->Thermo);
foreach ($comTemperatures as $value) {
if ($thermostatus[$value] == 0) {
echo $temperatures[$value];
}
}
Example at: https://eval.in/859257
I want to calculate avg in laravel using three table joins I've joined the tables perfectly and got the response from it but now I want to calculate the avg as well as count from the response I have got and then pass it to API response what should I do to achieve this?
Query i have tried
$individualScore= StatisticsMaster::with(['ratings',])->where('ratingsFor',$request->profileId)->get();
StatisticsMaster.php
public function ratings() {
return $this->hasMany(StatisticsChild::class,'statisticsMasterId','statisticsMasterId')->with('score');
}
StatisticsChild.php
public function score() {
return $this->belongsTo(Skill::class,'skillId','skillId');
}
public function getSkillNameAttribute(){
return $this->score->skillName;
}
DB Structure I have
tblSkills
->skillId
->skillName
->skillStatus
tblStatisticsMaster
->statisticsMasterId
->ratingsFor
->ratingsBy
->status
tblStatisticsChild
->statisticsChildId
->skillId
->statisticsMasterId
->individualScore
->statisticsStatus
I have got this response
{
"meta": {
"code": "200",
"message": "Skill Fetched Successfully."
},
"data": {
"skills": [
{
"statisticsMasterId": 1,
"ratingsFor": 1,
"ratingsBy": 6,
"score": 60.8,
"ratings": [
{
"skillId": 1,
"individualScore": 86,
"statisticsStatus": 1,
"skillName": "Shooting"
},
{
"skillId": 2,
"individualScore": 70,
"statisticsStatus": 1,
"skillName": "Dribbling"
},
{
"skillId": 3,
"individualScore": 54,
"statisticsStatus": 1,
"skillName": "Passing"
},
{
"skillId": 4,
"individualScore": 44,
"statisticsStatus": 1,
"skillName": "Defense"
},
{
"skillId": 5,
"individualScore": 50,
"statisticsStatus": 1,
"skillName": "Good Teammate"
}
]
},
{
"statisticsMasterId": 2,
"ratingsFor": 1,
"ratingsBy": 2,
"score": 52,
"ratings": [
{
"skillId": 1,
"individualScore": 50,
"statisticsStatus": 1,
"skillName": "Shooting"
},
{
"skillId": 2,
"individualScore": 50,
"statisticsStatus": 1,
"skillName": "Dribbling"
},
{
"skillId": 3,
"individualScore": 60,
"statisticsStatus": 1,
"skillName": "Passing"
},
{
"skillId": 4,
"individualScore": 50,
"statisticsStatus": 1,
"skillName": "Defense"
},
{
"skillId": 5,
"individualScore": 50,
"statisticsStatus": 1,
"skillName": "Good Teammate"
}
]
}
]
}
}
and the response I want.
{
"meta": {
"code": "200",
"message": "Skill Fetched Successfully."
},
"data": {
"skills": [
{
"statisticsMasterId": 1,
"ratingsFor": 1,
"ratingsBy": 6,
"score": 56.4,
"ratings": [
{
"skillId": 1,
"individualScore": 86,
"statisticsStatus": 1,
"skillName": "Shooting"
},
{
"skillId": 2,
"individualScore": 70,
"statisticsStatus": 1,
"skillName": "Dribbling"
},
{
"skillId": 3,
"individualScore": 54,
"statisticsStatus": 1,
"skillName": "Passing"
},
{
"skillId": 4,
"individualScore": 44,
"statisticsStatus": 1,
"skillName": "Defense"
},
{
"skillId": 5,
"individualScore": 50,
"statisticsStatus": 1,
"skillName": "Good Teammate"
}
]
}
]
}
}
where all the individual score contains the avg of all the ratings I'm using eloquent I want to do this in eloquent itself. how can I achieve this?
Thanks in advance :)
My data table that is loading its body from another file with ajax is giving me the invalid JSON error, but when I check my developer tools under network responses my JSON is valid?
This is my PHP and SQL:
<?php
header('Content-Type: application/json');
$output = array('data' => array());
$query = "SELECT * FROM table";
$stmt = sqlsrv_query($sapconn2, $query);
$x = 1;
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
$output['data'][] = array(
'col_1' => $x,
'ID' => $row['ID'],
'QuoteID' => $row['QuoteID'],
'CardCode' => $row['CardCode'],
'SlpCode' => $row['SlpCode'],
'SlpName' => $row['SlpName'],
'BandA' => $row['BandA'],
'NewPrice' => $row['NewPrice']
);
$x ++;
}
echo json_encode($output);
?>
This is my JSON thats returned in the browser:
{
"data": [
[1, 138, 25, "000123", "222", "test data", 222, 222],
[2, 144, 25, "000123", "132", "test data", 465, 789],
[3, 160, 25, "000123", "456132", "test data", 5599, 5499],
[4, 171, 25, "000123", "789", "test data", 7897, 989],
[5, 172, 25, "000123", "11111", "test data", 1, 11],
[6, 182, 25, "000123", "132166", "test data", 1323, 133],
[7, 183, 25, "000123", "135456", "test data", 1332132, 13213],
[8, 184, 25, "000123", "1321", "test data", 5643214, 6513]
]
}
EDIT:
var testTable = $("#testTable").DataTable({
processing: false,
serverSide: true,
dataType : 'json',
ajax: "test.php",
columns: [
{ "data": "col_1" },
{ "data": "ID" },
{ "data": "QuoteID" },
{ "data": "CardCode" },
{ "data": "SlpCode" },
{ "data": "SlpName" },
{ "data": "BandA" },
{ "data": "NewPrice" }
]
});
This is what datatable waits for:
{
"data": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
...
]
}
The "data" element is an array of objects, instead you pass an array of array.
You need something like that:
{
"data": [
{ "id": 1, "second_field": 138, "third_field": 25, "fourth_field": "000123", ... },
{ "id": 2, "second_field": 138, "third_field": 25, "fourth_field": "000123", ... },
]
}
EDITED:
$output['data'][] = array(
'col_1' => $x,
'col_2' => $row['ID'],
'col_3' => $row['QuoteID'],
'col_4' => $row['CardCode'],
'col_5' => $row['SlpCode'],
'col_6' => $row['SlpName'],
'col_7' => $row['BandA'],
'col_8' => $row['NewPrice']
);
When you make a request to a server-side script from DataTables with processing set to true then it sends this data.
When it returns data DataTables expects the data to follow these conventions.
You can either take these into account with your server-side script (there's a good example here.) or choose a different method for adding your data. If you perhaps set processing to false you might find everything just works as you expect.
Hope that helps.
I am currently using php to develop a website about steam which can fetch the user's profile and make player cards and so on. I am using the Steam Web Api to help me getting the information I want. Problem is, when I intend to acquire the user's badges, I use the "IPlayerService/GetBadges/v1" api, and it returns a json data like this:
{
"response": {
"badges": [
{
"badgeid": 23,
"level": 300,
"completion_time": 1434209651,
"xp": 125,
"scarcity": 0
},
{
"badgeid": 18,
"level": 15,
"completion_time": 1404061200,
"xp": 100,
"scarcity": 102167
},
{
"badgeid": 2,
"level": 3,
"completion_time": 1457872741,
"xp": 500,
"scarcity": 1334304
},
{
"badgeid": 13,
"level": 57,
"completion_time": 1356099851,
"xp": 260,
"scarcity": 5832743
},
{
"badgeid": 1,
"level": 3,
"completion_time": 1356099851,
"xp": 150,
"scarcity": 76725893
},
{
"badgeid": 1,
"appid": 231430,
"level": 3,
"completion_time": 1455540973,
"xp": 300,
"communityitemid": "817099833",
"border_color": 0,
"scarcity": 20438
},
{
"badgeid": 1,
"appid": 24010,
"level": 1,
"completion_time": 1403487961,
"xp": 100,
"communityitemid": "828384582",
"border_color": 0,
"scarcity": 15404
},
{
"badgeid": 1,
"appid": 35450,
"level": 1,
"completion_time": 1403573788,
"xp": 100,
"communityitemid": "842044372",
"border_color": 0,
"scarcity": 122236
},
{
"badgeid": 1,
"appid": 63380,
"level": 1,
"completion_time": 1403574599,
"xp": 100,
"communityitemid": "842169975",
"border_color": 0,
"scarcity": 222048
},
{
"badgeid": 1,
"appid": 303700,
"level": 1,
"completion_time": 1403743093,
"xp": 100,
"communityitemid": "866824198",
"border_color": 0,
"scarcity": 998614
},
{
"badgeid": 17,
"appid": 335590,
"level": 1,
"completion_time": 1420075581,
"xp": 100,
"communityitemid": "1438441936",
"border_color": 0,
"scarcity": 858393
},
{
"badgeid": 1,
"appid": 105450,
"level": 1,
"completion_time": 1451207235,
"xp": 100,
"communityitemid": "2454848086",
"border_color": 0,
"scarcity": 49755
},
{
"badgeid": 1,
"appid": 220200,
"level": 1,
"completion_time": 1451207275,
"xp": 100,
"communityitemid": "2454853894",
"border_color": 0,
"scarcity": 100821
},
{
"badgeid": 2,
"appid": 425280,
"level": 3,
"completion_time": 1451805075,
"xp": 300,
"communityitemid": "2483562201",
"border_color": 0,
"scarcity": 297565
},
{
"badgeid": 1,
"appid": 206440,
"level": 1,
"completion_time": 1451805331,
"xp": 100,
"communityitemid": "2549522337",
"border_color": 0,
"scarcity": 43807
},
{
"badgeid": 1,
"appid": 391220,
"level": 1,
"completion_time": 1455372224,
"xp": 100,
"communityitemid": "2699515873",
"border_color": 0,
"scarcity": 16843
},
{
"badgeid": 1,
"appid": 287390,
"level": 1,
"completion_time": 1457355907,
"xp": 100,
"communityitemid": "2764853882",
"border_color": 0,
"scarcity": 35158
}
]
,
"player_xp": 2735,
"player_level": 18,
"player_xp_needed_to_level_up": 65,
"player_xp_needed_current_level": 2600
}
}
This returned data only tells me about the badgeid and appid, and says nothing about the url of the badge image. I checked the badge image on steam, it's url is like http://cdn.akamai.steamstatic.com/steamcommunity/public/images/items/105450/472be31927c4e77721fcba33bbd04b1331272e7e.png
so I can not get the url just by the appid.
Since the steam web api can not fulfill my intention, I try to use php curl the request the steam user's profile page and badge page to acquire the information I need, and my code is:
$url='http://steamcommunity.com/profile/76561198078931851';
$postFields='';
$cookie='';
$header=array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*//*;q=0.8', 'Accept-Encoding:gzip, deflate, sdch', 'Accept-Language:zh-CN,zh;q=0.8', 'Cache-Control:max-age=0', 'Connection:keep-alive','Host:steamcommunity.com', 'Upgrade-Insecure-Requests: 1','User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36');
$btch=curl_init($url);
curl_setopt($btch, CURLOPT_FAILONERROR, 0);
curl_setopt($btch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($btch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($btch, CURLOPT_TIMEOUT, 1);
curl_setopt($btch, CURLOPT_ENCODING, 'gzip,deflate,sdch'); // 防止乱码
curl_setopt($btch, CURLOPT_HEADER, 1);
curl_setopt($btch, CURLOPT_COOKIE, $cookie);
curl_setopt($btch, CURLOPT_HTTPHEADER, $header);
curl_setopt($btch, CURLOPT_HTTPGET, 1);
try{
$result=curl_exec($btch);
}
catch(exception $e)
{
echo $e->getMessage();
}
if(!$result)
{
echo 'false!';
}
echo '<pre>';
print_r($result);
echo '</pre>';
curl_close($btch);
The curl did work, but steam never return the user's profile page and instead always redirects the request to the homepage of steam community and asks me to login.Therefore I can not proceed to fetch user profile.
I read the following related question:
Steam Web API get Badge Image URL
Does anybody knows anything about how to solve this problem and could you provide me some help? Great thanks in advance!
It seems that I find a way myself to solve the problem...just using
file_get_contents() instead of curl to request the steam user profile page. :)
Simply i have queried an api to return some data for a game. The result is an array where each set contains epoch datecreated field.
Using php i want to be able to filter out all the data for only data containing datecreated > 1444639042(epoch time).
How is that possible?
I am using leaguewrap from github as my class to pull data so:
// Get Match History
$game = $api->game();
$games = $game->recent($loluser);
returns:
{
"games": [
{
"fellowPlayers": [
{
"championId": 84,
"teamId": 200,
"summonerId": 4972120
},
{
"championId": 23,
"teamId": 200,
"summonerId": 1011313
},
{
"championId": 18,
"teamId": 100,
"summonerId": 456905
},
{
"championId": 77,
"teamId": 100,
"summonerId": 2751172
},
{
"championId": 131,
"teamId": 100,
"summonerId": 5100445
},
{
"championId": 1,
"teamId": 200,
"summonerId": 841536
},
{
"championId": 99,
"teamId": 200,
"summonerId": 4400359
},
{
"championId": 18,
"teamId": 200,
"summonerId": 3652614
},
{
"championId": 80,
"teamId": 100,
"summonerId": 600691
}
],
"gameType": "MATCHED_GAME",
"stats": {
"totalDamageDealtToChampions": 17713,
"goldEarned": 11117,
"item1": 3174,
"wardPlaced": 15,
"totalDamageTaken": 19563,
"item0": 1056,
"trueDamageDealtPlayer": 4,
"physicalDamageDealtPlayer": 10423,
"trueDamageDealtToChampions": 4,
"killingSprees": 1,
"playerRole": 2,
"totalUnitsHealed": 3,
"playerPosition": 4,
"level": 16,
"magicDamageDealtToChampions": 16682,
"turretsKilled": 2,
"magicDamageDealtPlayer": 81369,
"neutralMinionsKilledEnemyJungle": 3,
"assists": 9,
"magicDamageTaken": 11659,
"numDeaths": 5,
"totalTimeCrowdControlDealt": 326,
"largestMultiKill": 1,
"physicalDamageTaken": 7526,
"sightWardsBought": 2,
"team": 100,
"win": false,
"totalDamageDealt": 91797,
"largestKillingSpree": 5,
"totalHeal": 2398,
"item4": 3135,
"item3": 3020,
"item6": 3340,
"item5": 3165,
"minionsKilled": 59,
"timePlayed": 2852,
"physicalDamageDealtToChampions": 1025,
"championsKilled": 5,
"trueDamageTaken": 377,
"goldSpent": 9620,
"neutralMinionsKilled": 3
},
"gameId": 107038398,
"ipEarned": 82,
"spell1": 3,
"teamId": 100,
"spell2": 7,
"gameMode": "CLASSIC",
"mapId": 11,
"level": 30,
"invalid": false,
"subType": "NORMAL",
"createDate": 1444289569012,
"championId": 99
}
]}