Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I finaly find sulution for my question .... but i think there might be much better way to do this ... still i want to share the answer here, so if someone is looking for same answer might get help, and yes if some one have better way to do this please suggest thx </p> <p>Here what i am doing </p> <p>1st make functions </p> <pre><code>function distance($lat1, $lon1, $lat2, $lon2, $unit) { //** this to calculate distance in Miles or Km $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } function uk_data_radious($coords, $radius){//** this to get result within certain radios for a postcode global $DBH; $STH = $DBH-&gt;prepare("SELECT DISTINCT cat10, ( 3959 * acos( cos( radians({$coords['Latitude']}) ) * cos( radians( cat8 ) ) * cos( radians( cat9 ) - radians({$coords['Longitude']}) ) + sin( radians({$coords['Latitude']}) ) * sin( radians( cat8 ) ) )) AS distance FROM uk_data HAVING distance &lt;= {$radius} ORDER BY distance"); $STH-&gt;bindValue(':postcode', "$postcode", PDO::PARAM_STR); $STH-&gt;setFetchMode(PDO::FETCH_ASSOC); $STH-&gt;execute(); return $STH; } function uk_data_pc_count($user_count){//*** this is to check if post code is in our database or not global $DBH; $STH = $DBH-&gt;prepare("SELECT * from uk_data where cat10 = :user_count"); $STH-&gt;bindValue(':user_count', $user_count, PDO::PARAM_STR); $STH-&gt;execute(); $row_count = $STH -&gt;rowCount(); return $row_count ; } function comp_post_code($cat, $comp_post_code){//** this to get result within postcode global $DBH; $STH = $DBH-&gt;prepare("SELECT * from uk_data where cat10 like :comp_post_code AND ( cat1 like :cat OR cat2 like :cat OR cat3 like :cat OR cat4 like :cat OR cat5 like :cat OR cat6 like :cat OR cat7 like :cat OR cat8 like :cat OR cat9 like :cat )") ; $STH-&gt;bindValue(':cat', "%$cat%", PDO::PARAM_STR); $STH-&gt;bindValue(':comp_post_code', "$comp_post_code%", PDO::PARAM_STR); $STH-&gt;execute(); $STH-&gt;setFetchMode(PDO::FETCH_ASSOC); return $STH; } </code></pre> <p>Now use it on page </p> <pre><code>$q = $_GET['id']; $pc = change_text(' ', '',$_GET['pc']); $qu = change_text(' ', '%', $q); $pc_o = array(); $comp_name = array(); $comp_phone = array(); $distance = array(); $Latitude = array(); $Longitude = array(); $post_code = array(); if(uk_data_pc_count($pc) &gt; 0 ){ $uk_data_ll = uk_data_ll($pc); while (($row = $uk_data_ll-&gt;fetch()) !== false) { $Latitude[] = $row['cat8']; $Longitude[] = $row['cat9']; } $coords = array('Latitude' =&gt; "$Latitude[0]", 'Longitude' =&gt; "$Longitude[0]"); $radius = 10; $uk_data_radious = uk_data_radious($coords,$radius,$q); while (($row = $uk_data_radious-&gt;fetch()) !== false) { /*echo $row['cat10'].' --- '.$row['distance'].'&lt;br&gt;';*/ $pc_o[] = $row['cat10']; $distance[] = $row['distance']; } foreach($pc_o as $pc_o){ $uk_data_radious = comp_post_code($q,$pc_o); while (($row = $uk_data_radious-&gt;fetch()) !== false) { $comp_name[] = $row['comp_name']; $comp_phone[] = $row['comp_phone']; $post_code[] = $row['cat10']; $distance_m[] = distance($Latitude[0],$Longitude[0],$row['cat8'],$row['cat9'],"M"); }} for($i=0, $count = count($comp_name);$i&lt;$count;$i++) { echo $post_code[$i].' - '.$comp_name[$i].' - '.$comp_phone[$i].' - '.round($distance_m[$i],2).' Miles&lt;br&gt;'; } }else {echo 'Wrong Post-Code Selected';} </code></pre> <p>thx hope this will help and hoping to get good suggestion;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload