Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81986

Editor - HAVING clause with calculated column

$
0
0

Using Editor - I have a calculated column (calculates distance from the current position using the Haversine formula):

Field::inst( '( 3959 * acos( cos( radians(:Latitude) ) * cos( radians( asset.lat ) ) * cos( radians( asset.lng ) - radians(:Longitude) ) + sin( radians(:Latitude) ) * sin( radians( asset.lat ) ) ) )', 'asset.distance')->set( false )

For the WHERE clause I have:

    ->where( function ( $q ) {
         $q->bind( ':Latitude', $_REQUEST["lat"] );
         $q->bind( ':Longitude', $_REQUEST["lng"] );
         $q->where( 'asset.lat', null, '!=');
         $q->where( 'asset.lng', null, '!=');
    } ) 

This works fine but I only want to show the closest markers. As chronologically WHERE comes before SELECT (and therefore the calculated column does not exist when the SELECT is performed), I would need to use HAVING. Is there any way to do this using the EDITOR libraries?

If it wasn't a calculated column I would obviously just add:

$q->where( 'asset.distance', 0.25, '<');

Viewing all articles
Browse latest Browse all 81986

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>