I have a PostGIS database with a geography column. I'd like to be able to use PHP to SELECT the geography so then I could run another query using ST_Distance to get the distance between the points. However, when I run
SELECT geog from locations;
I get a weird value of 6 instead of the HEX output (something like 0101000020E6100000C442AD69DEAD5740575BB1BFEC6E3D40 is what I'm expecting). When I use the same query in phpPgAdmin I get the expected output, but not from my PHP script :(
I'd really appreciate any help :)
Thank you,
elshae
EDIT
$locations_result = @pg_query($DBConnect, "SELECT geog from locations;");
if (!$locations_result) {
echo "An error occurred upon getting data from the locations table.\n";
exit;
}
$i = 0;
while ($locations_arr = pg_fetch_row($locations_result)) {
$locations['location'][$i] = $locations_arr[0];
echo $locations['location'][$i];
$i++;
}
EDIT2 So now I am trying to select the geography right into the ST_Distance function so that it can just get the geography result directly, something like:
SELECT ST_Distance(geog_a, geog_b) FROM(SELECT geog AS geog_a FROM location WHERE id=123 UNION SELECT geog AS geog_b FROM location WHERE id=345);
But my SQL syntax is wrong and I have yet to figure out how I can get the result I'm aiming for. The UNION is putting these values into one column, which is what I have already. Instead I need something like:
geog_a |geog_b
----------------
hdsklgh|shfksh