php - Merge these 2 MySQL query into one -


i explain problem. have 2 tables : "listing" contain lists different informations , particulary 1 : city id. have second table "city" contain complete list of cities of countries many informations : latitude, longitude, city name, etc.

i want show listing ordered distance between actual point (geolocalised, have lat/lng) , cities in listing table.

actualy, 2 mysql queries, , it's work :

$formula = "(6366*acos(cos(radians($latitude))*cos(radians(`latitude`))*cos(radians(`longitude`) -radians($longitude))+sin(radians($latitude))*sin(radians(`latitude`))))";          $q = "select *,$formula dist ".$this->db_city." $formula<='$distance' order dist asc";         $q = $this->db->query($q); $resultsql = $q->result_array(); 

and 1 :

if ($localization != ''){             if ($whereclause == ''){                 //$whereclause .= ' address_city "'.$localization.'"';                 $loc = '';                 foreach ($localization $key => $value) {                     if ($loc == ''){                         $loc .= '"'.$value.'"';                     }else{                         $loc .= ', "'.$value.'"';                     }                 }                 $whereclause .= ' address_city in ('.$loc.')';             }else{                 //$whereclause .= ' && address_city "'.$localization.'"';                 $loc = '';                 foreach ($localization $key => $value) {                     if ($loc == ''){                         $loc .= '"'.$value.'"';                     }else{                         $loc .= ', "'.$value.'"';                     }                 }                 $whereclause .= ' && address_city in ('.$loc.')';             }         }          $q = "select * ".$this->db_listing.$whereclause." order created_stamp desc"; 

it's work, problem don't have "dist" parameter accessible in second query, can't order dist. solution merge first big query (the 1 formula) second.

i tried left join, didn't work. can me please ? !

try this, going return cities in radius of $distance provided longitude , latitudes.

"select *,(((acos(sin(($latitude*pi()/180)) * sin((`latitude`*pi()/180))+cos(($latitude*pi()/180)) * cos((`latitude`*pi()/180)) * cos((($longitude-      `longitude`)*pi()/180))))*180/pi())*60*1.1515) distance location (((acos(sin(($latitude*pi()/180)) * sin((`latitude`*pi()/180))+cos(($latitude*pi()/180)) * cos((`latitude`*pi()/180)) * cos((($longitude-      `longitude`)*pi()/180))))*180/pi())*60*1.1515) <= $distance" 

thanks.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -