$sql="SELECT ? FROM ? WHERE `stationid` = ? AND `sensid`=?"; #$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($qdbcols,$table,$stationId,$sensorId );