Trying to retrieve information from an API and display it in a table.
[php]
Current Dublin Bus Times.
Stop Number: [/php][php]<?php
$stopID = $_GET[‘stopid’];
$url = “https://data.dublink…rmation?stopid=” . $_GET[‘stopid’] . “&format=json”;
// Process the JSON and check for errors
$json = file_get_contents($url);
$array = json_decode($json,true);
if ($stopID != $array[“stopid”]) {
// Get the values for $errorCode and $errorMessage
$errorCode = $array[“errorcode”];
$errorMessage = $array[“errormessage”];
echo "Error: ";
echo $errorCode;
echo $errorMessage;
} else {
// Get the values
$duetime = $array[“duetime”];
$destination = $array[“destination”];
$route = $array[“route”];
echo "
| Stop Number | Route | Due Time | Destination | ”;
|---|---|---|---|
| " . $stopID . “ | ” . $route . “ | ” . $duetime . “ | ” . $destination . “ |
}
?>
[/php]