$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;