【发布时间】:2020-07-18 02:30:00
【问题描述】:
下面是代码:
<div class="device_data">
<div class="device_data_container">
<table>
<th> Sr No. </th>
<th> Device Name </th>
<th> Sensor Mac ID </th>
<th> Minimum </th>
<th> Maximum </th>
<th> Ambient </th>
<th> Average </th>
<th> Date Time </th>
</tr>
<?php
$sql = "SELECT device_id,device_name,sensor_mac_id,t_min,t_max,t_amb,t_avg,date FROM device_data WHERE device_name='Sky' ";
$result =mysqli_query($conn,$sql);
//$row=mysqli_fetch_array($result);
if (mysqli_num_rows($result)>0) {
// output data of each row
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td>'.$row['device_id'].'</td>';
echo '<td>'.$row['device_name'].'</td>';
echo '<td>'.$row['sensor_mac_id'].'</td>';
echo '<td>'.$row['t_min'].'</td>';
echo '<td>'.$row['t_max'].'</td>';
echo '<td>'.$row['t_amb'].'</td>';
echo '<td>'.$row['t_avg'].'</td>';
echo '<td>'.$row['date'].'</td>';
echo '</tr>';
}echo '</table>';
}else{
echo '0 result';
}
mysqli_close($conn);
?>
</table>
</div>
</div>
</div>
<div class="TabbedPanelsContent">
<table>
<th> Sr No. </th>
<th> Device Name </th>
<th> Sensor Mac ID </th>
<th> Minimum </th>
<th> Maximum </th>
<th> Ambient </th>
<th> Average </th>
<th> Date Time </th>
</tr>
<?php
$sql = "SELECT device_id,device_name,sensor_mac_id,t_min,t_max,t_amb,t_avg,date FROM device_data WHERE device_name='Rocky' ";
$result =mysqli_query($conn,$sql);
//$row=mysqli_fetch_array($result);
if (mysqli_num_rows($result)>0) {
// output data of each row
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td>'.$row['device_id'].'</td>';
echo '<td>'.$row['device_name'].'</td>';
echo '<td>'.$row['sensor_mac_id'].'</td>';
echo '<td>'.$row['t_min'].'</td>';
echo '<td>'.$row['t_max'].'</td>';
echo '<td>'.$row['t_amb'].'</td>';
echo '<td>'.$row['t_avg'].'</td>';
echo '<td>'.$row['date'].'</td>';
echo '</tr>';
}echo '</table>';
}else{
echo '0 result';
}
mysqli_close($conn);
?>
</table>
</div>
错误:
警告:mysqli_query(): 无法获取 mysqli in C:\xampp\htdocs\temp\details.php 第 212 行
警告:mysqli_num_rows() 期望参数 1 为 mysqli_result, 第 214 行 C:\xampp\htdocs\temp\details.php 中给出的 null 结果 0 结果 警告:mysqli_close():无法获取 mysqli C:\xampp\htdocs\temp\details.php 在第 232 行
我能够从名为 Sky 但不能使用 Rocky 的第一台设备获取数据
【问题讨论】:
-
考虑在单个查询中获取两个设备的结果
标签: php mysql mysqli html-table