doufangmu9087 2019-04-29 02:59
浏览 32

将数据库数据保存在php数组中并处理数据

I have more than one devices sending data to the database at the same time. even though I have a primary id for database, as there are more than one devices, selection of a particular value with primary id seems really hard. I have the unique names of each device (A, B, C etc.) i am diplaying data in a php table. the table will have headings like |Serial number| voltage| current| Select|. here serial number has no any relationship with database. I use it to organize data in the php table. When user select a value say serial number 3, previous 5 values should be considered for avg calculation, here values with serial 3,4,5,6 and 7. my doubt is how to choose these particular serial values?. I was thinking of saving these table in a php array and use these serials as key values. Any suggestions?

<?php
   $conn= mysqli_connect( $dbhost, $dbuser, $dbpass, $db );
    if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
    }

    $sql = "SELECT Date, Voltage, Current FROM DataTable WHERE ID='A' ORDER BY Date DESC";

    $result = $conn->query($sql);
//$i is used to assign serial number for each row
    $i=1;
    if ($result->num_rows > 0) {
     while($row = $result->fetch_assoc()) {
    echo "<form action = 'samepage.php' method =get>";

        echo "<tr>

            <td>" . $i. "</td>
            <td>" . $row["Time"]. "</td>
            <td>" . $row["Voltage"] . "</td>
            <td>" . $row["Current"]. "</td>
            <td>"." <input type=hidden  name=serialSelected value =" . $i."</td>
            <td>"." <input type=submit    name=Submit value=select >"."  </td>
        </tr>";
        $i++;
    echo "</form>";
  }
  echo "</table>";
  } else { echo "0 results"; }

  $avgCurrent=0;
  $avgVoltage=0;


  if(isset ($_GET['serialSelected'])){
//how to choose the value selected and the previous 4 values (total 5 values for avg calculation)

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图