0

This question already has an answer here:

How can I use this query with joomla 3 with limit to 3

SELECT * , (3956 * 2 * ASIN(SQRT( POWER(SIN(( $coorlat - latitude) *  pi()/180 / 2), 2) +COS( $coorlat * pi()/180) * COS(latitude * pi()/180) * POWER(SIN(( $coorlng - longitude) * pi()/180 / 2), 2) ))) as distance
from places
order by distance

marked as duplicate by mickmackusa Aug 26 at 23:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please familiarise yourself with Joomla query building methods and educate yourself on secure query practices. Start here: docs.joomla.org/Secure_coding_guidelines#Secure_on_search then continue reading the many [mysql] tagged pages on this site. You should only SELECT the columns that you require in your result set. – mickmackusa Aug 26 at 23:53
0

I found solution my code is :

$query = "SELECT * , (3956 * 2 * ASIN(SQRT( POWER(SIN(( $coorlat - latitude) *  pi()/180 / 2), 2) +COS( $coorlat * pi()/180) * COS(latitude * pi()/180) * POWER(SIN(( $coorlng - longitude) * pi()/180 / 2), 2) ))) as distance from places order by distance LIMIT 3";
        $db = JFactory::getDBO();
        $db->setQuery($query); 
        $articles = $db->loadObjectList(); 
        foreach($articles as $article) 
        {
            echo $article->title .'<br>';
        }
  • There are several unadvisable techniques implemented in this answer. More research is necessary. – mickmackusa Aug 26 at 23:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.