# Iterate over all sensorIds of one sensortype foreach $j ( @{${$sens}{$i}->{"sensorids"}} ){ $dbColName=$dbcols; # The sensorids defined by the user in latest_th[] may be of the format # sensorId.stationid. Here we have to split both values to get the right data ($sensorId, $station)=split(/\./o, $j, 2); $stationId=$station if( length($station) ); # Only start sql query if there are dbcols to be retrieved by the sensors # description and if this value is != "-" (rainsensor). The rainsensor is # handled differently below if( length($dbcols) && $dbcols ne "-" ){ $sql="SELECT $qdbcols FROM $table WHERE stationid = $stationId AND sensid=$sensorId"; #$sql.=" ORDER by datetime DESC,id DESC LIMIT 2"; $sql.=" ORDER by datetime DESC LIMIT 2"; # Query database for min, max and average of sensor $sth = $dbh->prepare($sql); $sth->execute; # Fetch the latest rows. We need two for values that encode a difference # like the rain sensor @res= $sth->fetchrow_array; # @res1=$sth->fetchrow_array if( ${$sens}{$i}->{"type"}=~/RA/o ); }