Multiple MYSQL Queries against one PHP variable -


i've broken down individual sql queries information want sql table i'm confused on how can combine statements agianst 1 variable. variable being used in php display data.

here sql queries i'm wanting run.

select * weather order stamp desc limit 1   select sum(rainfall) weather stamp >= curdate()) total_rainfall  select max(maxwind) weather stamp >= curdate()) max_windspeed  select max(temperature) weather stamp >= curdate()) max_temperature  select min(temperature) weather stamp >= curdate()) min_temperature 

here current query gives me want except max windspeed, max temperature, , minimum temperature last 24 hours.

 select *, (select sum(rainfall) weather stamp >= curdate()) total_rainfall weather order stamp desc limit 1 

basically, i'm wanting add maximum temperature, minimum temperature , maximum windspeed occured within current date.

mysql data table example

here way i'm trying display data using php.

<?php  $url1=$_server['request_uri'];  header("refresh: 60; url=$url1");  $connectinfo = mysql_connect("***", "***", "***") or die(mysql_error());  mysql_select_db("raspberrydb001", $connectinfo);  $sql = "select *, (select sum(rainfall) weatherdata stamp >= curdate()) total_rainfall weatherdata order stamp desc limit 1; ";   $result = mysql_query($sql, $connectinfo);  while($row = mysql_fetch_array($result)) {  $windspeed = $row['windspeed']; $maxwind = $row['maxwind']; $temperature = $row['temperature']; $humidity = $row['humidity']; $rainfall = $row['rainfall']; $stamp = $row['stamp']; $d=mktime(); $total_rainfall = $row['total_rainfall'];  echo "<div style='text-align:center'><h5>temperature:  " . $temperature . "(f)" . "<br>" . "rainfall: " . $total_rainfall . "(in)" . "<br>" . "wind: " . $windspeed . "(mph)" . "<br>" .  "humidity: " . $humidity . "(%)" . "<br>" .  "</h5></div>"; echo "<div style='text-align:right'><h6>updated at: " . $stamp . "</h6></div>"; echo "<br>";  }  ?> 

thanks

i propose split 2 queries.

first, collect data:

select * weather order stamp desc limit 1  

second, collect min/max data:

select     sum(rainfall) total_rainfall,      max(maxwind) max_windspeed,      max(temperature) max_temperature,      min(temperature)  min_temperature       weather stamp >= curdate()) limit 1 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -