SRL Archive - Help

PHP: Help.


NexPB

2012-02-10 12:49:48

How can I get the vars from SRL-stats? With php ofcourse :D

Kyle Undefined

2012-02-10 12:52:49

SRL stats has an API that creates a JSON object when called, you just have to call that API and parse it with the PHP.

NexPB

2012-02-10 13:16:13

From: Kyle Undefined
SRL stats has an API that creates a JSON object when called, you just have to call that API and parse it with the PHP.


I don't know how to parse JSON never used it before :s

Kyle Undefined

2012-02-10 13:19:02

PHP has a built in object that parses it for you :)

NexPB

2012-02-10 13:32:35

From: Kyle Undefined
PHP has a built in object that parses it for you :)


I have this but how can I get now each var individual?
[PHP]$jsonurl = "http://stats.villavu.com/api/script/667";
$json1 = file_get_contents($jsonurl);
$data = json_decode($json1, TRUE);[/PHP]

NexPB

2012-02-11 18:52:25

Bump this is what I have so far
[PHP]$jsonurl = "http://stats.villavu.com/api/script/667";

$json = file_get_contents($jsonurl);
$data = json_decode($json, TRUE);
$dump = var_dump($data);
$result = $data["vars"][0][0];[/PHP]

Kyle Undefined

2012-02-11 20:49:04

This is how I'm doing it on my page to display the stat vars:

[PHP]$data = @file_get_contents("http://stats.villavu.com/api/script/".$id);
if(!$data){
die("Failure retrieving data.");
}
$data = @json_decode($data);

if(!$data){
die("Invalid data format.");
}

foreach($data as $key => $value){
$$key = $value;
}

foreach($vars as $var){
$options .= "<td style='width:21%;'><input type=\"checkbox\" value=\"{$var[1]}\" id=\"{$var[0]}\" />{$var[1]}</td>";
}[/PHP]

var[0] is the ID of the stat var, and var[1] is the name.

NexPB

2012-02-12 08:03:00

From: Kyle Undefined
This is how I'm doing it on my page to display the stat vars:

[PHP]$data = @file_get_contents("http://stats.villavu.com/api/script/".$id);
if(!$data){
die("Failure retrieving data.");
}
$data = @json_decode($data);

if(!$data){
die("Invalid data format.");
}

foreach($data as $key => $value){
$$key = $value;
}

foreach($vars as $var){
$options .= "<td style='width:21%;'><input type=\"checkbox\" value=\"{$var[1]}\" id=\"{$var[0]}\" />{$var[1]}</td>";
}[/PHP]

var[0] is the ID of the stat var, and var[1] is the name.


Thanks.