Page 1 of 1

Min and Max value for current date

Posted: Wed Jan 05, 2011 5:19 am
by meteo021
I have database with meteorogical data and I extract some data from last row and put it in html table http://www.webwork.host56.com/
For Min and Max temp I need min and max value for current day (date).
How can I achieve that task and how to store these values in my html table.
Here is the part of my code:

Code: Select all

$query="SELECT * FROM  trosarina ORDER BY id DESC LIMIT 1";
$trosarina=mysql_query($query);

echo "<table border='1'>";
echo "<tr> <th>Lokacija</th> <th>Datum</th> <th>Vreme</th> <th>Temperatura</th> <th>Max temp</th> <th>Min temp</th> <th>Vlaznost</th> <th>Pritisak</th> <th>Pravac vetra</th> <th>Brzina vetra</th> <th>Max udar vetra</th></tr>";

$row = mysql_fetch_array($trosarina) or die(mysql_error());
	
	echo "<tr><td>"; 
	echo $row['Lokacija'];
	echo "</td><td>"; 
	echo $row['Datum'];
	echo "</td><td>"; 
	echo $row['Vreme'];
		echo "</td><td>"; 
	echo $row['Temperatura'];
		echo "</td><td>"; 
	echo $row['Max_Temp'];
		echo "</td><td>"; 
	echo $row['Min_Temp'];
		echo "</td><td>"; 
	echo $row['Vlaznost'];
		echo "</td><td>"; 
	echo $row['Pritisak'];
	echo "</td><td>"; 
	echo $row['Pravac_vetra'];
	echo "</td><td>"; 
	echo $row['Brzina_vetra'];
	echo "</td><td>"; 
	echo $row['Max_udar_vetra'];
	echo "</td></tr>"; 

?>

Re: Min and Max value for current date

Posted: Wed Jan 05, 2011 5:22 am
by VladSun
Describe your "trosarina" table structure first...

Re: Min and Max value for current date

Posted: Wed Jan 05, 2011 8:32 am
by meteo021
You can figure it out fromthis part of code:

Code: Select all

$data1 = curl("http://www.meteos.rs/ams/trosarina/downld02.txt");
$data1 = explode("\n", trim($data1, "\n"));
unset($data1[0], $data1[1], $data1[2]);

foreach($data1 as $d1){
    $d1 = preg_replace("/(\s){2,}/", "','", trim($d1)); 
    $query1 = "INSERT INTO trosarina (Datum,Vreme,Temperatura,Max_Temp,Min_Temp,Vlaznost,Element7,Element8,Pravac_vetra,Brzina_vetra,Max_udar_vetra,Element12,Element13,Element14,Element15,Element16,Pritisak,Element18,Element19,Element20,Element21,Element22,Element23,Element24,Element25,Element26,Element27,Element28,Element29,Element30,Element31,Element32,Element33,Element34,Element35,Element36,Element37,Element38,Element39,Element40,Element41,Element42,Element43,Element44,Element45,Element46)VALUES('$d1');";
  mysql_query($query1);
}

Re: Min and Max value for current date

Posted: Wed Jan 05, 2011 8:46 am
by VladSun

Code: Select all

SELECT 
    max(`Max_Temp`), 
    min(`Min_Temp`) 
from 
    trosarina 
where 
    Datum='2011-01-02' 
group by 
    Datum

Re: Min and Max value for current date

Posted: Wed Jan 05, 2011 10:21 am
by meteo021
Since these data are from txt file retrieved with curl function Column 'Datum' is VARCHAR . I could change it but I am afraid what if the data are old (due to mailfunction of meteorological station for example), that column would indicate like data are fresh.
Can you also help me with second part of my problem: putting min and max value in html table.