donglu2523 2019-01-11 07:37 采纳率: 100%
浏览 42

有没有办法使用在子文件夹中的后台运行的php脚本的输出更改div背景颜色?

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
";
    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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动