$5 and elevation < $6 and (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) and lat < $1 and lat > $2 and lon < $3 and lon > $4 order by elevation desc", array($lat1,$lat2,$lon1,$lon2,$elevbottom,$elevtop)) or die('Query failed: ' . pg_last_error()); $array = array(); while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { $array[] = $line; } echo json_encode($array); pg_free_result($result); } } } } } } } } // Close database connection when needed if (isset($dbconn)) { pg_close($dbconn); } ?>