27 lines
1006 B
PHP
27 lines
1006 B
PHP
<?php
|
|
// Connecting, selecting database
|
|
$dbconn = pg_connect("host=localhost dbname=nws user=nws password=nws")
|
|
or die('Could not connect: ' . pg_last_error());
|
|
|
|
// Performing SQL query
|
|
$query = "SELECT cwa,lat,lon,lastimage,county,elevation,camid,state,description,hydro,airport FROM cams WHERE active <> false AND lastsuccess IS NOT NULL AND (EXTRACT(EPOCH FROM (current_timestamp - lastsuccess ))/60) < (interval + 20) order by elevation desc";
|
|
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
|
|
|
|
// Printing results in HTML
|
|
$array = array();
|
|
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
|
|
// Ensure hydro is a proper boolean
|
|
$line['hydro'] = ($line['hydro'] === 't' || $line['hydro'] === true);
|
|
// Ensure airport is a proper boolean
|
|
$line['airport'] = ($line['airport'] === 't' || $line['airport'] === true);
|
|
$array[] = $line;
|
|
}
|
|
echo json_encode($array);
|
|
|
|
// Free resultset
|
|
pg_free_result($result);
|
|
|
|
// Closing connection
|
|
pg_close($dbconn);
|
|
?>
|