I have a weather-reading database where I store all data for consumption by a webpage that shows the MAX and MIN pressure.
The problem is that I like to show the time and date in which these values where recorded.
Code I use to read MAX pressure:
$max_out_pressure = mysql_query("SELECT MAX(out_pressure) AS out_pressure FROM $table");
$max_out_pressure = mysql_result($max_out_pressure,0,"out_pressure");
$max_out_pressure = substr($max_out_pressure, 0, 6);
echo "$max_out_pressure";
echo "mbar";
I have the columns ID
, Datetime
, Pressure
, Temperature
Table is named readings
Webpage: http://temperatur.co.nf/readings.php
之前从未制作过数据库或网页,所以我在努力解决这个问题。
答案 0 :(得分:0)
这将获得最大压力和记录日期。
$sql = "SELECT out_pressure, Datetime
FROM $table
ORDER BY out_pressure DESC
LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$max_out_pressure = $row['out_pressure'];
$max_date = $row['Datetime'];