0

I have a main PHP page inside of which I have links to more than 50 other pages. In each second page I have some devices from 7 to 15 (nb is not the problem), for every device I have a script that reads from a database the state of each device (online, offline or dead) and for each state the div background color changes. Now I want the div background color in the main page to change if any of the devices in the second page has a change of state so I can go into the page and see which device changes and fix the problem.

This is the second page

<div class = "masa-1" id = "id1">
    <div <?php $nm = 'em-644'; ?> <?php include 'statusBDE.php'; ?>  class = "miniOlm-1" id = "miniOlm-1" <?php echo $color5; ?>; >EM-644</div>
    <div <?php include 'statusBDE.php';  $nm = 'em-645'; ?>  class = "miniOlm-2" id = "miniOlm-2" <?php echo $color5; ?>; >EM-645</div>
    <div <?php include 'statusBDE.php';  $nm = 'em-646'; ?>  class = "miniOlm-3" id = "miniOlm-3" <?php echo $color5; ?>; >EM-646</div>
</div>

<div class = "masa-2" id = "id2">
    <div <?php include 'statusBDE.php'; $nm = 'em-647'; ?> class = "miniOlm-4" id = "miniOlm-4" <?php echo $color5; ?>; >EM-647</div>
    <div <?php include 'statusBDE.php'; $nm = 'em-648'; ?> class = "miniOlm-5" id = "miniOlm-5" <?php echo $color5; ?>; >EM-648</div>
</div>

<div class = "masa-3" id = "id3">
    <div <?php include 'statusBDE.php'; $nm = 'em-649'; ?> class = "miniOlm-6" id = "miniOlm-6" <?php echo $color5; ?>; >EM-649</div>
    <div <?php include 'statusBDE.php'; $nm = 'em-650'; ?> class = "miniOlm-7" id = "miniOlm-7" <?php echo $color5; ?>; >EM-650</div>
    <div <?php include 'statusBDE.php'; $nm = 'em-651'; ?> class = "miniOlm-8" id = "miniOlm-8" <?php echo $color5; ?>; >EM-651</div>
</div>

And the script for it

<?php
  include 'connStr.php';    

  global $nm;    

  $status = pg_query($db, "SELECT * FROM hosts");

  if (!$status) {
    echo "Error\n";
    exit;
  }

  while ($row = pg_fetch_row($status)) {
    if ($row[0] == $nm) {
      if ($row[4] == 1 && $row[6] == 1 | $row[6] == 0) {
        //$color5 = "#0961ef"; //albastru
        $color5 = 'style="background: #0961ef;"';
        $sts = '0'; 
      }
      elseif ($row[4] == 0 & $row[6] == 1) {
        //$color5 = "#f40c0c"; //rosu
        $color5 = 'style="background: #f40c0c;"';
        $sts = '1';
      }
      elseif ($row[4] == 0 & $row[6] == 0) {
        //$color5 = "#f4f40c"; //galben
        $color5 = 'style="background: #f4f40c;"';
        $sts = '2';
      }
      else{
        //$color5 ="#f40c0c"; //rosu
        $color5 = 'style="background: #f40c0c;"';
        $sts = '3';
      }
    }
  }

Now this is loading when I open the page from the main page with onclick event, everything works just fine, I need the status from this script to change in the same time the div from the main page. Is the a way to do that? I'm open to any suggestions, thanks.

Yom T.
  • 8,760
  • 2
  • 32
  • 49
jOvy
  • 1
  • 1
  • You can push notifications of updates when you change a device state. This means your client application isn't constantly polling your server to see if anything has changed. Have a look [here](https://stackoverflow.com/questions/35473356/is-there-any-javascript-tcp-soket-library-for-php-like-signalr-with-net) for some examples. – Reinstate Monica Cellio Jan 11 '19 at 07:48
  • not helping to be fair, all the devices (name`s and ip add) are stored in the db, in the db is a function that pings all the ip`s (>600 of them) and stores the status in a table, same table that i use to read the status, i just need a way to change that div live(or on autorefresh) depending on the status – jOvy Jan 11 '19 at 12:36
  • Your database pings the IP addresses? Lol. In that case (which is insanely ridiculous), you need to simply `setTimeout()` and make an API call the get the state of all devices periodically. Once you've updated the page, create another `setTimeout()`. That's the best you'll get since you're working with something ridiculous! – Reinstate Monica Cellio Jan 11 '19 at 12:45
  • i know (found it like this so i need to deal with it so far) i`ll try to see how it goes, thank you, if any other ideas pls let me know – jOvy Jan 11 '19 at 13:22
  • I think you're stuck with that, but at least it's a pretty basic solution. Good luck :) – Reinstate Monica Cellio Jan 11 '19 at 13:46

0 Answers0