I do not understand your select formula, but it seems to me that you have to introduce a zone function by which you can GROUP users BY zones and then select only the first (or n-th) user from each group. So the question is: What exactly is a zone?
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
SELECT *,(((acos(sin((".$lat."*pi()/180)) * sin((`lat`*pi()/180))+cos((".$lat."*pi()/180)) * cos((`lat`*pi()/180))* cos(((".$lon."- `lon`)*pi()/180))))*180/pi())*60*1.1515) AS dist_x FROM `message` HAVING dist_x<=".$distance." AND dist_x<=$distance ORDER BY dist_x ASC limit 1"
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376