【发布时间】:2013-03-25 21:00:14
【问题描述】:
我有一个数据库和表来获取 OID 结果并将它们插入到表中。这个表里面有多种类型的值,我需要最终表能够区分它们。我将结果按分组排序,并通过mysql_fetch_array() 将结果过滤到表格中。
这就是我在代码方面的优势。
$result = mysql_query("SELECT MAX(t1)AS t1, device, test, value FROM ACRC WHERE test='Fan Speed' GROUP BY device, test ORDER BY device ASC, test ASC LIMIT 4");
echo "<table border='3' cellpadding='3'>
<tr>
<th>Timestamp</th>
<th>Unit</th>
<th>Test</th>
<th>Result</th>
</tr>
<tbody>";
while($row = mysql_fetch_array($result))
{
echo"<tr>";
echo"<td>". $row['t1']. "</td>";
echo"<td>". $row['device']. "</td>";
echo"<td>". $row['test']. "</td>";
echo"<td>". $row['value']." %</td>";
echo"</tr>";
}
$result = mysql_query("SELECT MAX(t1)AS t1, device, test, value FROM ACRC WHERE test<>'Fan Speed' GROUP BY device, test ORDER BY test ASC, device ASC LIMIT 8");
while($row = mysql_fetch_array($result))
{
echo"<tr>";
echo"<td>". $row['t1']. "</td>";
echo"<td>". $row['device']. "</td>";
echo"<td>". $row['test']. "</td>";
echo"<td>". $row['value']." F</td>";
echo"</tr>";
}
echo"</table>";
此设置当前有效,但我想使用 if/then/else 语句将其压缩为一个 mysql_fetch_array(),因为只要风扇速度在测试列中,该值就会在其表的末尾添加一个 %正方形,每当温度出现在测试列中时,我需要一个 F 出现在值正方形中。数据当前在我的数据库中存储为一个简单的整数。
--------------------
|Fan Speed | 55 % |
----------------------
|Temperature| 70 F |
--------------------
【问题讨论】:
标签: php mysql arrays html-table