PHP Wrapper Formatting

Hi all,

I have a small php script that connects to the UptimeRobot API and displays a simple table to show if my site routers are online. This can be seen working here http://www.pvmon.uk/status/index.php

I am not a coder and have never done anything with php but I have managed to style the table with CSS in a fashion and I am happy with it. The only problem I have is the time stamp. I want the time stamp in a row at the very bottom of the table, and in a smaller bold font. I am happy to apply the style once it is in the correct place but I cannot get anything to work when trying to add a bottom table row. PHP code for the page below…

[php]

Satellite Status <?php echo ""; echo date (" H:i:s", time()); $apiKey = "u228191-95d5c8ca79a9ee954affa60e"; $url = "http://api.uptimerobot.com/getMonitors?apiKey=" . $apiKey . "&format=xml"; $xml = file_get_contents($url); $xml = new SimpleXMLElement($xml); foreach($xml->monitor as $monitor) { echo ""; echo "
Satellite Status
"; echo $monitor['friendlyname']; echo " "; if ($monitor['status'] == 2) { echo "Online"; } elseif ($monitor['status'] == 9) { echo "Offline"; } elseif ($monitor['status'] == 0) { echo "Paused"; } else { echo "Not Available"; } } echo "
"; ?> [/php]

Can anyone please help?

Many thanks,

Bret

I’ve neatened your code up a little. Your problem was you were outputting the timestamp at the top of the table, not the bottom:

[PHP]

Satellite Status <?php

//Create a variable holding the API key
$apiKey = “u228191-95d5c8ca79a9ee954affa60e”;

//Define the API URL
$url = “http://api.uptimerobot.com/getMonitors?apiKey=” . $apiKey . “&format=xml”;

//Place items from URL into variable
$xml = file_get_contents($url);

//Create an XML element using the items
$xml = new SimpleXMLElement($xml);

//Loop through results
foreach($xml->monitor as $monitor) {

//Create a switch statement using the status codes of the satellites
switch ($monitor['status']){

	//Satellite is online
	case "2":
		$status = '<a style="color:green;">Online</a>';
	break;

	//Satellite is offline
	case "9":
		$status = '<a style=\"color:red;">Offline</a>';
	break;

	//Satellite is paused
	case "0":
		$status = '<a style="color:blue;">Paused</a>';
	break;

	//Default - Not available
	default:
		$status = 'Not Available';
	break;

}

//Output the results
echo '<tr>
	<td>' . $monitor['friendlyname'] . '</td><td>' . $status . '</td>
      </tr>';

}
//Output current timestamp
echo ’



';

?>

Satellite Status
Last Updated ’ . date (" H:i:s", time()) . ’
[/PHP]
Sponsor our Newsletter | Privacy Policy | Terms of Service