-1
I’m still new to this area of Web programming, I’m managing here,
I have a code that performs the ping test of some hosts and returns whether they are online or not. However I saw in another code I found on the Web that it is possible to update an individual row in the table and uses a spinner to show that the line is being updated.
<?php
$title = "Monitora"; // website's title
$servers = array(
'HOST 1' => array(
'ip' => '10.65.1.1',
'info' => 'HOST 1',
),
'HOST 2' => array(
'ip' => '10.65.2.2',
'info' => 'HOST 2',
),
'HOST 3' => array(
'ip' => '10.65.3.3',
'info' => 'HOST 3',
),
)
?>
<!doctype html>
<html lang="en">
<head>
<style>
</style>
<meta charset="UTF-8">
<title><?php echo $title; ?></title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/2.3.2/cosmo/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<style type="text/css">
/* Custom Styles */
</style>
</head>
<body>
<div class="container">
<h1><?php echo $title; ?></h1>
<table class="table">
<thead>
<tr>
<th></th>
<th>Nome</th>
<th>Host</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($servers as $name => $server) :
$ip = $server['info'];
exec("ping -n 2 $ip", $output, $status);
if ($status == 0) {
$status_ping = "success";
} else {
$status_ping = "error";
}
?>
<tr class="<?php echo $status_ping ?>">
<td><i class="icon-spinner icon-spin icon-large"></i></td>
<td class="name"><?php echo $name; ?></td>
<td><?php echo $server['info']; ?></td>
<td><?php echo $status_ping ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</body>
</html>
And what is the doubt?
– Franklin Barreto
@Franklinbarreto I don’t know how to update the table row individually...
– Diogo Gumeiro
You are only ping once when the page is loaded. there is no way to update just one row ai. You will just double check by refreshing the page again. you can for example separate the php check from the front and make an ajax request to register 5 seconds for all rows of the table that are still pending
– André Walker
Tries to put an id on the lines you need to update, the logic is the same.
– user219228