Jump to content

php host status from php mysql database


dumb2champ
Go to solution Solved by Barand,

Recommended Posts

Help me!!

Seem when i run the scripts, the output seems wrong :(

 

This is the output...

CG5XdYa.png?1

The 1st and 3rd entry is true, online

 

But the rest should be OFFLINE but the output shows all ONLINE

 

I think the problem is from foreach loop but I cannot figure out how to solve the problem

 

Please help me... :(

<?php
include 'connector/connect.php';
?>
<meta http-equiv="refresh" content="6" >
<style>
    tbody > tr:nth-child(2n+1) > td, tbody > tr:nth-child(2n+1) > th {
        background-color: #ededed;
    }
    table{
        width: 70%;
        margin: auto;
        border-collapse: collapse;
        box-shadow: darkgrey 3px;
    }
    thead tr {
        background-color: #36c2ff;
    }
</style>

<h1 align="center">Server Availability</h1>

<table border="1">
    <thead>
	
        <tr>
	    <th>Entry</th>
            <th>Host</th>
            <th>Name</th>
            <th>Location</th>
            <th>Description</th>
            <th>Availability</th>
        </tr>
		
    </thead>
	
	<tbody>
	
    <?php
    $sql = "SELECT * FROM host_entry";
    $no  = 1;
	
    $dbhi = $dbh->query($sql);

    foreach ($dbhi->fetchAll(PDO::FETCH_BOTH) as $data) {
    ?>
        <tr>
            <td><?php echo $no++; ?></td>
            <td><?php echo $data['host_server']; ?></td>
            <td><?php echo $data['host_name']; ?></td>
            <td><?php echo $data['host_location']; ?></td>
            <td><?php echo $data['host_desc']; ?></td>
			<td>
		<?php  
			$ip = $data["host_server"];
			
                        // Run the ping to the IP
			exec ("ping -n 1 -w 1 $ip", $ping_output);

			if(preg_match("/Reply/i", $ping_output[2])) {
			    echo "<font color='green'><strong>Online!</strong></font>";
			}else{
			    echo "<font color='red'><strong>Offline!</strong></font>";
			}
						
                ?>
			</td>
        </tr>
    <?php
    }
    ?>
	
    </tbody>
</table>
Link to comment
Share on other sites

Barand, the scripts work great..:)

 

I want to ask you, does my exac command in foreach..loop work at right way or not??

What i mean was, I want to create a ping sites that display status of ip/server...

It include other computer, servers, website, and so on...

 

So i use this this exac command to ping to other ip/server...

if ok...could you suggest we or give examples of well writing exac command in foreach??

 

if not, its ok...i`m just asking..:)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.