I'm using the Fortnite Tracker API to get some data from my site, I have it working with by once connected it'll export my current data into a JSON file. This has worked fine for the mean time I have it working with a couple of the stats but for some reason I can't get it to work with recent matches, can someone see where I'm going wrong here?
PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/psn/mygamertag");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'TRN-Api-Key: myapikey'
));
$response = curl_exec($ch);
curl_close($ch);
$fp = fopen("myStats.json", "w");
fwrite($fp, $response);
fclose($fp);
$data = json_decode(file_get_contents("myStats.json"));
$solo = $data->stats->p2;//solos data
$duos = $data->stats->p10;//duos data
$squads = $data->stats->p9;//squads data
$matches = $data->recentMatches;//match data
$sesh1 = $matches[0]->id->valueInt;
$solo_wins = $solo->top1->valueInt;
$duos_wins = $duos->top1->valueInt;
$squads_wins = $squads->top1->valueInt;
$solo_matches = $solo->matches->valueInt;
$duos_matches = $duos->matches->valueInt;
$squads_matches = $squads->matches->valueInt;
$solo_kd = $solo->kd->valueDec;
$duos_kd = $duos->kd->valueDec;
$squads_kd = $squads->kd->valueDec;
$solo_games = $solo->matches->valueInt;
$duos_games = $duos->matches->valueInt;
$squads_games = $squads->matches->valueInt;
$solo_kills = $solo->kills->valueInt;
$duos_kills = $duos->kills->valueInt;
$squads_kills = $squads->kills->valueInt;
$total_matches = ($solo_matches+$duos_matches+$squads_matches);
$total_wins = ($solo_wins+$duos_wins+$squads_wins);
$total_kills = ($solo_kills+$duos_kills+$squads_kills);
$total_kd = (round($total_kills/($total_matches-$total_wins),2));
echo 'Total Matches: '.$total_matches.'<br>';
echo 'Total Wins: '.$total_wins.'<br>';
echo 'Total Kills: '.$total_kills.'<br>';
echo 'Total KD: '.$total_kd.'<br>';
echo $sesh1;
?>
JSON File - Solo (This works fine with the PHP)
{
"stats": {
"p2": {
"score": {
"label": "Score",
"field": "Score",
"category": "General",
"valueInt": 31960,
"value": "31960",
"rank": 3045650,
"percentile": 47.0,
"displayValue": "31,960"
},
"top1": {
"label": "Wins",
"field": "Top1",
"category": "Tops",
"valueInt": 4,
"value": "4",
"rank": 1904807,
"percentile": 42.0,
"displayValue": "4"
},
"top3": {
"label": "Top 3",
"field": "Top3",
"category": "Tops",
"valueInt": 0,
"value": "0",
"rank": 1,
"displayValue": "0"
},
"top10": {
"label": "Top 10",
"field": "Top10",
"category": "Tops",
"valueInt": 44,
"value": "44",
"rank": 1923906,
"percentile": 9.0,
"displayValue": "44"
},
"top25": {
"label": "Top 25",
"field": "Top25",
"category": "Tops",
"valueInt": 79,
"value": "79",
"rank": 2519315,
"percentile": 11.0,
"displayValue": "79"
},
"kd": {
"label": "K/d",
"field": "KD",
"category": "General",
"valueDec": 0.71,
"value": "0.71",
"rank": 5155051,
"percentile": 63.0,
"displayValue": "0.71"
},
"matches": {
"label": "Matches",
"field": "Matches",
"category": "General",
"valueInt": 127,
"value": "127",
"rank": 4270142,
"percentile": 59.0,
"displayValue": "127"
},
"kills": {
"label": "Kills",
"field": "Kills",
"category": "General",
"valueInt": 87,
"value": "87",
"rank": 4376486,
"percentile": 58.0,
"displayValue": "87"
},
}
]
}
JSON File - Recent Matches (Struggling to pull data in the PHP)
{
"recentMatches": [
{
"id": 149942602,
"accountId": "9e9e2e92-870c-4596-a4a0-1276b16d2b2e",
"playlist": "p9",
"kills": 1,
"minutesPlayed": 0,
"top1": 0,
"top5": 0,
"top6": 0,
"top10": 0,
"top12": 0,
"top25": 0,
"matches": 1,
"top3": 0,
"dateCollected": "2018-04-18T08:09:28.963",
"score": 290,
"platform": 2,
"trnRating": 767.6,
"trnRatingChange": -103.23
},
{
"id": 148934320,
"accountId": "9e9e2e92-870c-4596-a4a0-1276b16d2b2e",
"playlist": "p9",
"kills": 1,
"minutesPlayed": 0,
"top1": 1,
"top5": 0,
"top6": 1,
"top10": 0,
"top12": 0,
"top25": 0,
"matches": 3,
"top3": 1,
"dateCollected": "2018-04-17T22:19:04.747",
"score": 865,
"platform": 2,
"trnRating": 870.8,
"trnRatingChange": -100.7124
},
{
"id": 147725308,
"accountId": "9e9e2e92-870c-4596-a4a0-1276b16d2b2e",
"playlist": "p9",
"kills": 0,
"minutesPlayed": 0,
"top1": 0,
"top5": 0,
"top6": 0,
"top10": 0,
"top12": 0,
"top25": 0,
"matches": 2,
"top3": 0,
"dateCollected": "2018-04-17T14:22:34.047",
"score": 423,
"platform": 2,
"trnRating": 906.0,
"trnRatingChange": -99.85293750000001
},
]
}
Being new to json, I had the same issue. To solve it I created a container for the recent matches.
$recent = $data->recentMatches;
This is an array of objects. So
echo $recent[1]->score;
would print '865', which is the score for the second match listed in your example.
Hope this helps.
Related
So I'm having a strange problem with Doctrine that I don't understand and need help with. Essentially, I am running quite a complex query due to the nature of my database and its various joins and for some reason the response when I grab try to grab all records from my database is returning my entities incorrectly.
See my doctrine query below:
$subQuery = $this->_em->createQueryBuilder()
->from(Product::class, 'ex')
->select('ppsi.id')
->join('ex.productSpecificationItems', 'ppsi')
->where('ex.id = p.id');
$subQuery = $subQuery->getDQL();
$subQuery2 = $this->_em->createQueryBuilder()
->from(Product::class, 'ex2')
->select('ppoiv.id')
->join('ex2.productOptionItemValues', 'ppoiv')
->where('ex2.id = p.id');
$subQuery2 = $subQuery2->getDQL();
$subQuery3 = $this->_em->createQueryBuilder()
->from(Product::class, 'ex3')
->select('poie.id')
->join('ex3.productOptionItems', 'poie')
->where('ex3.id = p.id');
$subQuery3 = $subQuery3->getDQL();
$qb = $this->createQueryBuilder('p')
->select('p, pc, psc, i, po, poi, poiv, ps, psi')
->join('p.productCategory', 'pc')
->leftJoin('p.productSubCategory', 'psc')
->leftJoin('p.images', 'i')
->leftJoin('p.productOptions', 'po')
->leftJoin('p.productSpecifications', 'ps')
->leftJoin('ps.productSpecificationItems', 'psi', Join::WITH, 'psi.id IN (' . $subQuery. ')')
->leftJoin('po.productOptionItems', 'poi', Join::WITH, 'poi.id IN (' . $subQuery3. ')')
->leftJoin('poi.productOptionItemValue', 'poiv', Join::WITH, 'poiv.id IN (' . $subQuery2. ')')
->addOrderBy('p.id', 'ASC');
The response of this causes some entities to have the productOptionItemValues either listed under the wrong productOptionItem, just causes blank records to return, or doesn't return them at all. See an example below (as a JSON for clarity):
{
"id": 373,
"name": "test",
"code": "test",
"url": "373-test",
"price": "1.00",
"stock": 1,
"description": "<p>fghfgh mnsdbfksdhfjk sd</p>\n",
"live": false,
"createdAt": "2022-03-17T14:45:35+00:00",
"updatedAt": "2022-03-17T15:12:44+00:00",
"featured": false,
"aggregateReviewScore": null,
"productCategory": {
"id": 2,
"name": "Hex Set Screws",
"url": "hex-set-screws"
},
"productSubCategory": {
"id": 12,
"name": "Nylon",
"url": "nylon"
},
"images": [],
"productOptions": [
{
"id": 1,
"name": "Colour",
"productOptionItems": {
"0": {
"id": 2,
"name": "Black",
"productOptionItemValue": [
{
"id": 1196,
"stock": 1,
"price": "1.00",
"useOwn": false
},
{
"id": 1201,
"stock": 1,
"price": "1.00",
"useOwn": false
},
{
"id": 1198,
"stock": 1,
"price": "1.00",
"useOwn": false
}
]
},
"1": {
"id": 8,
"name": "Yellow",
"productOptionItemValue": [
{
"id": 1197,
"stock": 1,
"price": "1.00",
"useOwn": false
}
]
},
"2": {
"id": 14,
"name": "Light Grey"
},
"3": null,
"4": {
"id": 15,
"name": "Mid Grey"
},
"7": null,
"8": {
"id": 20,
"name": "Light Blue"
},
"11": null,
"12": {
"id": 22,
"name": "Purple"
},
"13": null
}
},
{
"id": 2,
"name": "Pack Size",
"productOptionItems": [
{
"id": 3,
"name": "10",
"productOptionItemValue": [
{
"id": 1180,
"stock": 100,
"price": "10.00",
"useOwn": true
}
]
},
{
"id": 4,
"name": "100",
"productOptionItemValue": [
{
"id": 1181,
"stock": 10,
"price": "1000.00",
"useOwn": true
}
]
}
]
}
],
"productSpecifications": []
}
If I run the same query on a SINGLE product (so the same Doctrine Query as a above just with a p.id = :id WHERE added) it returns absolutely fine. See the response for that below (and the CORRECT response I am looking for):
{
"id": 373,
"name": "test",
"code": "test",
"url": "373-test",
"price": 1,
"stock": 1,
"description": "<p>fghfgh mnsdbfksdhfjk sd</p>\n",
"live": false,
"createdAt": "2022-03-17T14:45:35+00:00",
"updatedAt": "2022-03-17T15:12:44+00:00",
"featured": false,
"aggregateReviewScore": null,
"productCategory": {
"id": 2,
"name": "Hex Set Screws",
"url": "hex-set-screws"
},
"productSubCategory": {
"id": 12,
"name": "Nylon",
"url": "nylon"
},
"images": [],
"productOptions": [
{
"id": 1,
"name": "Colour",
"productOptionItems": [
{
"id": 2,
"name": "Black",
"productOptionItemValue": {
"id": 1196,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 7,
"name": "Red",
"productOptionItemValue": {
"id": 1201,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 8,
"name": "Yellow",
"productOptionItemValue": {
"id": 1197,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 14,
"name": "Light Grey",
"productOptionItemValue": {
"id": 1202,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 15,
"name": "Mid Grey",
"productOptionItemValue": {
"id": 1205,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 20,
"name": "Light Blue",
"productOptionItemValue": {
"id": 1203,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 22,
"name": "Purple",
"productOptionItemValue": {
"id": 1204,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 23,
"name": "Natural",
"productOptionItemValue": {
"id": 1198,
"stock": 1,
"price": 1,
"useOwn": false
}
}
]
},
{
"id": 2,
"name": "Pack Size",
"productOptionItems": [
{
"id": 3,
"name": "10",
"productOptionItemValue": {
"id": 1180,
"stock": 100,
"price": 10,
"useOwn": true
}
},
{
"id": 4,
"name": "100",
"productOptionItemValue": {
"id": 1181,
"stock": 10,
"price": 1000,
"useOwn": true
}
}
]
}
],
"productSpecifications": []
}
Any help or ideas would be greatly appreciated!
I'm very new to the world of APIs and am currently trying to display all reviews I have on my reviews.io account for a specific product. I've tried to make the following script, which now seems to work, however, I would love to have the results sorted nicely in a for-each loop.
Here my current script:
<?php
$header_data = array(
'store' => 'MYSHOP',
'apikey' => 'MYKEY',
'method' => 'GET'
);
$ch = curl_init();
$curlOpts = array(
CURLOPT_URL => 'https://api.reviews.co.uk/product/review?store=MYSHOP&sku=TSCB20&apikey=MYKEY',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $curlOpts);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: 0'));
$rv = curl_exec($ch);
$data = json_decode($rv,true);
curl_close($ch);
?>
This outputs all reviews in Raw code or JSON I believe, however, I would like to have them displayed nicely in a div for each item.
The output is as follows (formatted):
{
"store": {
"name": "",
"logo": ""
},
"stats": {
"average": "5.0000",
"count": 2
},
"reviews": {
"total": 2,
"per_page": 15,
"current_page": 1,
"last_page": 1,
"from": 1,
"to": 2,
"data": [
{
"votes": null,
"flags": null,
"title": "David",
"product_review_id": 2978412,
"review": "...is beautiful and I had a great time on this tour. Already started to plan my next trip with them",
"sku": "TSCB20",
"rating": 5,
"date_created": "",
"order_id": "",
"timeago": "",
"reviewer": {
"first_name": "David",
"last_name": "",
"verified_buyer": "yes",
"address": "",
"profile_picture": "",
"gravatar": "38677a4e8a55189055d6e5bf2efa9ade"
},
"ratings": [],
"replies": [],
"images": [],
"product": {
"sku": "TSCB20",
"name": "",
"description": "",
"link": "",
"image_url": "",
"mpn": "",
"brand": null,
"category": null,
"custom": null
},
"author": {
"email": "david#"
}
},
{
"votes": null,
"flags": null,
"title": null,
"product_review_id": 2978009,
"review": "Exceeded expectations on all fronts cultural and Food ",
"sku": "TSCB20",
"rating": 5,
"date_created": "",
"order_id": "RGFY4ZG",
"timeago": "",
"reviewer": {
"first_name": "Alan",
"last_name": "",
"verified_buyer": "yes",
"address": "",
"profile_picture": "",
"gravatar": "64e2ac644a158b76a82f9e1c5c2886f5"
},
"ratings": [],
"replies": [],
"images": [],
"product": {
"sku": "TSCB20",
"name": "",
"description": "",
"link": "",
"image_url": "",
"mpn": "",
"brand": null,
"category": null,
"custom": null
},
"author": {
"email": ""
}
}
]
},
"ratings": [],
"settings": {
"write_review_button": 1,
"disable_product_seo_css": 0,
"show_product_review_titles": 0
},
"word": "Excellent",
"products": [
{
"sku": "TSCB20",
"name": ""
}
],
"write_review_link": ""
}
My ideal outcome now would be a loop, that fetches the reviewer's name, the review itself and the star-rating. e.g.
<p class="review">Review here</p>
<p class="reviewer">Name here</p>
<p class="rating">Rating here</p>
So technically based on the current output, I should have 2 reviews. Some expert help would be greatly appreciated as I am very new to APIs. Thank you very much in advance.
Simple foreach() will do the job:
<?php foreach($data['reviews']['data'] as $dat){?>
<p class="review"><?php echo $dat['review'];?></p>
<p class="reviewer"><?php echo trim($dat['reviewer']['first_name'].' '.$dat['reviewer']['last_name']);?></p>
<p class="rating"><?php echo $dat['rating'];?></p>
<?php }?>
if you see this code:
use ResponseHandler;
public function search(SoundFilter $soundFilter) {
$sounds = Sound::query();
$sounds->filter($soundFilter);
// dd($sounds->toSql());
$sounds = $sounds->paginate(1);
$this->setResponseStatus(1);
$this->setResponseStatusCode(200);
$this->setResponseData([
'sounds' => new SoundsCollection($sounds),
]);
$this->ajaxResponse();
return $this->response();
}
i want soundsCollection($sounds) returen paginate result but it will send only data
{
"status": 1,
"messages": [],
"statusCode": 200,
"data": {
"sounds": [
{
"id": 1,
"name": "منی که عشق با روضه فهمیدم",
"slug": "",
"type": 2,
"description": "<p dir=\"rtl\" style=\"text-align:center\"><strong>متن شعر<\/strong><\/p>",
"likes": 0,
"downloads": 0,
"views": 0,
"created_at": "2019-08-02 20:09:45",
"updated_at": "2019-08-03 18:45:49",
"sort_order": 0,
"status": 1,
}
]
}
}
but when i do this code :
$sounds = Sound::query();
$sounds->filter($soundFilter);
// dd($sounds->toSql());
$sounds = $sounds->paginate(1);
$this->setResponseStatus(1);
$this->setResponseStatusCode(200);
// $this->setResponseData([
//// 'sounds' => new SoundsCollection($sounds),
//// ]);
$this->ajaxResponse();
return new SoundsCollection($sounds);
i will get pagination result
{
"data": [
{
"id": 1,
"name": "منی که عشق با روضه فهمیدم",
"slug": "",
"type": 2,
"description": "<p dir=\"rtl\" style=\"text-align:center\"><strong>متن شعر<\/strong><\/p>",
"likes": 0,
"downloads": 0,
"views": 0,
"created_at": "2019-08-02 20:09:45",
"updated_at": "2019-08-03 18:45:49",
"sort_order": 0,
"status": 1,
}
],
"links": {
"first": "http:\/\/madahi.test\/api\/v1.0\/search?page=1",
"last": "http:\/\/madahi.test\/api\/v1.0\/search?page=3",
"prev": null,
"next": "http:\/\/madahi.test\/api\/v1.0\/search?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 3,
"path": "http:\/\/madahi.test\/api\/v1.0\/search",
"per_page": 1,
"to": 1,
"total": 3
}
}
which function i should call or waht i should do to get same result but with my custom response handler how to force collection return paginate result
i want i have link, meta in first result
i found it and share it for other people if have same problem:
because i use seprate ResponseHandler and it will reutrn an JsonResponse object
it is the data i send to resposnse with responseHandler
// trait : ResponseHandler.php
new JsonResponse($json, $json['statusCode'], $this->headers);
and when i call this code it will retun another JsonResponse
'sounds' => new SoundsCollection($sounds),
// Or
'sounds' => (new SoundsCollection($sounds))->toResponse($request)
so the above JsonResponse will ignore pagination data the solution is :
'sounds' => (new SoundsCollection($sounds))->toResponse($request)->getData()
and it will work
{
"status": 1,
"messages": [],
"statusCode": 200,
"data": {
"sounds": {
"data": [
{
"id": 1,
"name": "منی که عشق با روضه فهمیدم",
"slug": "",
"type": 2,
"description": "<p dir=\"rtl\" style=\"text-align:center\"><strong>متن شعر<\/strong><\/p>",
"likes": 0,
"downloads": 0,
"views": 0,
"created_at": "2019-08-02 20:09:45",
"updated_at": "2019-08-03 18:45:49",
"sort_order": 0,
"status": 1,
}
],
"links": {
"first": "http:\/\/madahi.test\/api\/v1.0\/search?page=1",
"last": "http:\/\/madahi.test\/api\/v1.0\/search?page=3",
"prev": null,
"next": "http:\/\/madahi.test\/api\/v1.0\/search?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 3,
"path": "http:\/\/madahi.test\/api\/v1.0\/search",
"per_page": 1,
"to": 1,
"total": 3
}
}
}
}
I have the table "orders" from woocommerce.
I filtered and get sorted the elements by status with GET request.
The results are copied to a JSON file.
So now, I want to find the elements with the same "product_id" and their values and summarize them to display in screen so I can print them.
For example:
"product_id": 45329,
"variation_id": 0,
"quantity": 1
"product_id": 48911,
"variation_id": 0,
"quantity": 1,
"product_id": 45329,
"variation_id": 0,
"quantity": 1
The output that I want to achieve is this:
45329 quantity 2
48911 quantity 1
Thanks!
Decode JSON with json_decode() and make calculations. Next example uses simplified JSON data, which I think matches the format from WooCommerce (I guess this format is from list orders GET request):
<?php
# JSON
$json = '
[
{
"id": 727,
"line_items": [
{
"id": 315,
"name": "Woo Single #1",
"product_id": 93,
"variation_id": 0,
"quantity": 2,
"tax_class": "",
"subtotal": "6.00",
"subtotal_tax": "0.45",
"total": "6.00",
"total_tax": "0.45",
"taxes": [
{
"id": 75,
"total": "0.45",
"subtotal": "0.45"
}
],
"meta_data": [],
"sku": "",
"price": 3
},
{
"id": 316,
"name": "Ship Your Idea – Color: Black, Size: M Test",
"product_id": 22,
"variation_id": 23,
"quantity": 1,
"tax_class": "",
"subtotal": "12.00",
"subtotal_tax": "0.90",
"total": "12.00",
"total_tax": "0.90",
"taxes": [
{
"id": 75,
"total": "0.9",
"subtotal": "0.9"
}
],
"meta_data": [
{
"id": 2095,
"key": "pa_color",
"value": "black"
},
{
"id": 2096,
"key": "size",
"value": "M Test"
}
],
"sku": "Bar3",
"price": 12
}
]
}
]';
$input = json_decode($json, true);
# Sum
$output = array();
foreach ($input as $order) {
foreach ($order["line_items"] as $item) {
$product_id = $item['product_id'];
$quantity = $item['quantity'];
if (!array_key_exists($product_id, $output)) {
$output[$product_id] = 0;
}
$output[$product_id] += $quantity;
}
}
#Output
foreach ($output as $key => $value) {
echo $key.' quantity '.$value.'<br>';
}
?>
Output:
93 quantity 2
22 quantity 1
Im having trouble extracting data from a API, i would like to use for a school project..
The link to the API i here
Or here's a sample of the API output
{
"help": "http://www.odaa.dk/api/3/action/help_show?name=datastore_search",
"success": true,
"result": {
"resource_id": "2a82a145-0195-4081-a13c-b0e587e9b89c",
"fields": [
{
"type": "int4",
"id": "_id"
},
{
"type": "text",
"id": "date"
},
{
"type": "text",
"id": "garageCode"
},
{
"type": "int4",
"id": "totalSpaces"
},
{
"type": "int4",
"id": "vehicleCount"
}
],
"records": [
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 62,
"_id": 1,
"totalSpaces": 65,
"garageCode": "NORREPORT"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 512,
"_id": 2,
"totalSpaces": 512,
"garageCode": "SKOLEBAKKEN"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 236,
"_id": 3,
"totalSpaces": 1240,
"garageCode": "SCANDCENTER"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 40,
"_id": 4,
"totalSpaces": 953,
"garageCode": "BRUUNS"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 2932,
"_id": 5,
"totalSpaces": 142,
"garageCode": "BUSGADEHUSET"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 18,
"_id": 6,
"totalSpaces": 383,
"garageCode": "MAGASIN"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 3,
"_id": 7,
"totalSpaces": 210,
"garageCode": "KALKVAERKSVEJ"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 255,
"_id": 8,
"totalSpaces": 700,
"garageCode": "SALLING"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 0,
"_id": 9,
"totalSpaces": 0,
"garageCode": "DOKK1"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 34,
"_id": 10,
"totalSpaces": 449,
"garageCode": "Navitas"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 105,
"_id": 11,
"totalSpaces": 105,
"garageCode": "NewBusgadehuset"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 9,
"_id": 12,
"totalSpaces": 319,
"garageCode": "Urban Level 1"
},
{
"date": "2015/11/11 03:50:07",
"vehicleCount": 15,
"_id": 13,
"totalSpaces": 654,
"garageCode": "Urban Level 2+3"
}
],
"_links": {
"start": "/api/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c",
"next": "/api/action/datastore_search?offset=100&resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c"
},
"total": 13
}
}
I would like to extract the cells called "vehicleCount" and "_id", but i seems I can't figure out how to do it :(
$json = file_get_contents('http://www.odaa.dk/api/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c');
$json = json_decode($json);
echo $json->fields->_id;
I have tried many different ways, but now loss of ideas and its 4 o'clock in the morning, so hopefully someone can help me.
if you want to extract the cells vehicleCount and _id
This is my solution for you:
<?php
$json = file_get_contents('http://www.odaa.dk/api/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c');
$json = json_decode($json);
foreach ($json->result->records as $val) {
echo "_id = " .$val->_id . " vehicleCount = " . $val->vehicleCount . "<br>";
}
?>
$json->result->records[0]->_id