如何使用SQL数据库在php中调用多查询
代码如下:如何使用SQL数据库在php中调用多查询,php,mysql,mysqli,html-table,Php,Mysql,Mysqli,Html Table,代码如下: <div class="device_data"> <div class="device_data_container"> <table> <th> Sr No. </th> <th> Device Name </th>
<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>
高级文书主任。
设备名
传感器Mac ID
最低限度
最大限度
环境的
平均的
日期时间
高级文书主任。
设备名
传感器Mac ID
最低限度
最大限度
环境的
平均的
日期时间
错误:
警告:mysqli_query():无法在中获取mysqli
第212行的C:\xampp\htdocs\temp\details.php
警告:mysqli_num_rows()要求参数1为mysqli_结果,
C:\xampp\htdocs\temp\details.php第214行的结果中给出了null
警告:mysqli_close():无法在中获取mysqli
第232行的C:\xampp\htdocs\temp\details.php
我可以从第一台名为Sky的设备上获取数据,但不能使用Rocky在第一次循环后,您已经关闭了连接 mysqli_close($conn) 请将其删除,并在项目中的其他位置正确关闭连接
顺便说一句,在项目中构建一个全局连接总是一个好主意。考虑在一个查询中获取两个设备的结果