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)
}