i was trying to google but I did'nt see something that helped me.
i'm using the Planetteamspeak API. For Example, I can do:
GET https://api.planetteamspeak.com/serverstatus/1.2.3.4:9987/
An example output is:
{
"status": "success",
"result": {
"name": "Planet TeamSpeak",
"users": 91,
"slots": 512,
"online": true,
"password": false
}
}
Can anyone give me a simple way to show this in an HTML/PHP table like this?
http://cdn.treudler.net/shared/screenshots/capture_20-01-2015-05-56-27.png
I'm a noob in Restful API's :c thank you so much!!!
<?php
$server = $_GET['serverstatus'];
$result = file_get_contents('https://api.planetteamspeak.com/serverstatus/'.$server.'/');
$result = json_decode($result);
?>
<h2>Server status</h2>
<table border=1>
<tr><td>Status</td><td><?=$result->status;?></td></tr>
<tr><td>Name</td><td><?=$result->result->name;?></td></tr>
<tr><td>Users</td><td><?=$result->result->users;?></td></tr>
<tr><td>Slots</td><td><?=$result->result->slots;?></td></tr>
.....
</table>
<!-------------------------------------------------------->
<?php
$server = $_GET['servernodes'];
$result = file_get_contents('https://api.planetteamspeak.com/servernodes/'.$server.'/');
$result = json_decode($result);
?>
<h2>Server Nodes</h2>
<table border=1>
<tr><td>Status</td><td><?=$result->status;?></td></tr>
<tr><td>Name</td><td><?=$result->result->name;?></td></tr>
<tr><td>Users</td><td><?=$result->result->users;?></td></tr>
<tr><td>Slots</td><td><?=$result->result->slots;?></td></tr>
.....
</table>
<!-------------------------------------------------------->
.... add as many variables / sections as you wish
The way to call the script:
https://ovh.treudler.net/api/index.php?serverstatus=1.2.3.4:9987&servernodes=1.4.6.8:9987
Keep adding &variable=value
to the URL as many times as you please
Planetteamspeak API returns Data in Json Format
you can do like this to get json data to array
$resultData = json_decode($data);
and then use HTML table and display data in it with PHP
echo $resultData->result->name;
I'm assuming $response is the response back from the rest call.
<?php
$response= file_get_contents('https://api.planetteamspeak.com/serverstatus/82.211.30.15:9987/%22');
$response = json_decode($response);
?>
<table style="width:100%">
<tr>
<td>General Information</td>
</tr>
<tr>
<td>Name: <?php echo $response->result->name;?></td>
</tr>
<tr>
<td>Status: <?php if($response->result->online == true){echo "Online";}else{echo "Offline";}?></td>
</tr>
<tr>
<td>Users Online: <?php echo $response->result->users;?></td>
</tr>
<tr>
<td>Users Online: <?php echo $response->result->users;?></td>
</tr>
<tr>
<td>Flags: </td>
</tr>
<tr>
<td>Last Update: <?php echo getdate()?> </td>
</tr>
</table>
<?php $result = json_decode($data,true)?>
<table border=1>
<tr><td>Status</td><td><?php echo $result['status'];?></td></tr>
<tr><td>Name</td><td><?php echo $result['name'];?></td></tr>
<tr><td>Users</td><td><?php echo $result['users'];?></td></tr>
<tr><td>Slots</td><td><?php echo $result['slots'];?></td></tr>
.....
</table>
I can't comment but I've been reading your comments here and realize that you may not actually know how to send the request itself in order to receive the data in the first place. There are a few ways which are outlined pretty well in answers to this question. How to send a GET request from PHP?