Using a mySQL SELECT AS Alias?
I'm trying to show a visitor to a page the 10 closest places to them by default. I've got most of it, but I can't figure out how I can use an Alias in my presentation.
I've got a Pod called 'places'. I've geocoded the addresses in 'places', and stored the coordinates in columns 'lat' and 'long'. I'm also doing a GeoIP lookup on my users, and storing their location in $usr_lat and $usr_long. (I promise to share how I'm doing all this when I get the bugs worked out).
Here's my code:
$Record = new Pod('places');
$params = array(
'select' => "t.*, ( 3959 * acos( cos( radians($lat) ) * cos( radians( t.lat ) )
* cos( radians( t.long ) - radians($long) ) + sin( radians($lat) )
* sin( radians( t.lat ) ) ) ) AS DISTANCE",
'orderby' => "DISTANCE ASC",
'limit'=>25,
'where'=>'t.publish AND t.lat IS NOT NULL'
);
$Record->findRecords($params);
while ($Record->fetchRecord()){
echo $Record->get_field('name') . " is " . $Record->get_field('DISTANCE'); . " miles away\n";
}
This doesn't work. How can I get access to DISTANCE? Thanks.
edited Oct 20 '10 at 11:37
1 Answer
Strange. The code above didn't work earlier when I tried it. I put a var_dump($Record) inside of my while loop, and sure enough there was a ["distance"]=> string(16) "14.0717238473029" sitting in there.
Running that same code posted above now returns My Place is 14.0717238473029 miles away.
I must have had needed to clear my cache or something.
edited Oct 20 '10 at 3:18


