TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Join Tables with Distance Calculation (http://www.talkphp.com/advanced-php-programming/5595-join-tables-distance-calculation.html)

oceanrockn 10-07-2010 07:24 PM

Join Tables with Distance Calculation
 
I am trying to join two tables together. First is a calendar of events with lat/lng sorted by distance. I also need to get the business information from the directory table.

This one works without joining the tables without the JOIN:

PHP Code:

$query "SELECT calendar.id,calendar.coupon,( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) AS distance FROM calendar HAVING distance < $miles"

This is the code that does not work, have tried many variations:

PHP Code:

$query "SELECT calendar.id,calendar.coupon,directory.business,( 3959 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) AS distance FROM calendar RIGHT JOIN directory ON calendar.id = directory.id HAVING distance < $miles"

If anyone can help it would be much appreciated

Village Idiot 10-11-2010 04:56 PM

Are you using MySQL? Join statement do not use HAVING, they use ON.


All times are GMT. The time now is 10:32 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0