prepare( 'select u.id,u.unit_group from st_parameters st,units u where st.id='.$param.' and st.st_unit=u.id' ); $qug -> execute(); while ($row = $qug -> fetch(PDO::FETCH_ASSOC)) { $from_unit = $row['id']; $unit_group = $row['unit_group']; } if (!empty($_COOKIE['unit_'.$unit_group])) { $to_unit=intval($_COOKIE['unit_'.$unit_group]); } else { $to_unit=$from_unit; } $qu = $db -> prepare( 'select u.name_short from units u where u.id='.$to_unit ); $qu -> execute(); while ($row = $qu -> fetch(PDO::FETCH_ASSOC)) { $param_unit = $row['name_short']; } return Array( 'from' => $from_unit, 'to' => $to_unit, 'name' => $param_unit ); } function convert_unit($db,$value,$from,$to) { if ($from==$to) { $val = $value; } else { $qv = $db -> prepare( 'select round(unitconv('.$value.','.$from.','.$to.'),2) res' ); $qv -> execute(); while ($row = $qv -> fetch(PDO::FETCH_ASSOC)) { $val = $row['res']; } } return $val; } $year = $_REQUEST['year']; $month = $_REQUEST['month']; $day = $_REQUEST['day']; if (! ($db = new PDO("mysql:host=$mysql_host;port=$mysql_port;dbname=$mysql_schema",$mysql_user,$mysql_pwd,array( PDO::ATTR_PERSISTENT => false)))) { die($err); } $db -> exec('SET CHARACTER SET utf8'); if (! $year) { $q = $db -> prepare( 'select date_format(day,\'%Y\') as year from calendar group by year order by year'); $q -> execute(); ?>

Архив метеоданных

fetch(PDO::FETCH_ASSOC)) { ?> Данные за год
prepare( 'select date_format(day,\'%m\') as month, date_format(day,\'%d\') as day from calendar where day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and day execute(); ?>

год

fetchAll(PDO::FETCH_ASSOC); $months = []; foreach ($data as $row) { $days [$year.$row['month'].$row['day']] = '&month='.$row['month'].'&day='.$row['day']; $months[$row['month']]=1; } $m = 1; echo ''; for ($i=1; $i<=3; $i++) { echo ''; for ($j=1; $j<=4; $j++) { echo ''; $m++; } echo ''; } echo '
'; $month=sprintf('%02d',$m); $month_name = strftime('%B',mktime(0,0,0,$month,1,$year)); if (!empty($months[$month])) { echo '

'.$month_name.'

'; } else { echo '

'.$month_name.'

'; } calendar($year,$month,$days,'?year='.$year.'%s',0); echo '
'; $next_year = $year+1; $q = $db -> prepare ( 'select s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name, count(distinct day) cnt, round(min(v.min),1) min_value, round(max(v.max),1) max_value, u.name_short unit from sensors_ranges v,sensors s,st_parameters p,units u where v.sensor=s.id and v.parameter=p.id and p.st_unit=u.id and v.day>=str_to_date(\''.$year.'-01-01\',\'%Y-%m-%d\') and v.day execute(); $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { $units = get_unit($db,$sensor['param']); $from_unit = $units['from']; $to_unit = $units['to']; $param_unit = $units['name']; $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit); $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit); echo '

'.$sensor['param_name'].'('.$sensor['sensor_name'].')

'; echo ''; echo ''; echo '
'; echo 'Минимальное значение за год '.$min_val.' '.$param_unit.'
'; echo 'Максимальное значение за год '.$max_val.' '.$param_unit.'
'; echo '
'; if ($sensor['cnt']>1) { echo '
'; } } } else { if (!$day) { $next_year = $year; $next_month = $month+1; if ($next_month == 13) { $next_month = 1; $next_year = $next_year+1; } $next_month = sprintf('%02d',$next_month); $next_year = sprintf('%04d',$next_year); $month = sprintf('%02d',$month); $year = sprintf('%04d',$year); $q = $db -> prepare( 'select date_format(day,\'%d\') as day from sensors_ranges where day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and day execute(); $data = $q -> fetchAll(PDO::FETCH_ASSOC); $month_name = strftime('%B %Y',mktime(0,0,0,$month,1,$year)); ?>

prepare ( 'select s.id sensor,p.id param,s.s_description sensor_name,p.st_description param_name, count(distinct day) cnt, round(min(v.min),1) min_value, round(max(v.max),1) max_value, u.name_short unit from sensors_ranges v,sensors s,st_parameters p,units u where v.sensor=s.id and v.parameter=p.id and p.st_unit=u.id and v.day>=str_to_date(\''.$year.'-'.$month.'-01\',\'%Y-%m-%d\') and v.day execute(); $sensors = $q -> fetchAll(PDO::FETCH_ASSOC); foreach ($sensors as $sensor) { $units = get_unit($db,$sensor['param']); $from_unit = $units['from']; $to_unit = $units['to']; $param_unit = $units['name']; $min_val = convert_unit($db,$sensor['min_value'],$from_unit,$to_unit); $max_val = convert_unit($db,$sensor['max_value'],$from_unit,$to_unit); echo '

'.$sensor['param_name'].'('.$sensor['sensor_name'].')

'; echo ''; echo ''; echo '
'; echo 'Минимальное значение за месяц '.$min_val.' '.$param_unit.'
'; echo 'Максимальное значение за месяц '.$max_val.' '.$param_unit.'
'; echo '
'; if ($sensor['cnt']>1) { echo '
'; } } } else { $month = sprintf('%02d',$month); $year = sprintf('%04d',$year); $day = sprintf('%02d',$day); $q = $db -> prepare( 'select distinct v.sensor as sensor_id,s.s_description,p.id as param_id,p.st_description from sensors_ranges v,st_parameters p,sensors s where v.day=str_to_date(\''.$year.'-'.$month.'-'.$day.'\',\'%Y-%m-%d\') and v.sensor=s.id and v.parameter=p.id' ); $q -> execute(); while ($row = $q -> fetch(PDO::FETCH_ASSOC)) { echo '

'.$row['s_description'].'/'.$row['st_description'].'

'; ?>