I have this error:
Fatal error: Uncaught Error: Call to a member function fetch() on boolean in distance() #1 {main} thrown on line 15
What I need to calculate is the distance between all the places in the table that every one have unique lat and long with one place that I defined and order them DESC and fetch photo and the title:
id |  Country |  photo  |  p_latitude |  p_longtitude
1     japan      1.jpg      32.125         35.123
2     Chian      2.jpg      56.125         50.123
3     USA        3.jpg      42.125         90.123
 function distance() {
        global $con;
    $lat1= 36.2048;
    $lang1= 138.2529;
    $query = 'SELECT *, CASE
        WHEN '. $lat1 .' = `p_latitude` && '. $lang1 .' = `p_longtitude` THEN  0 ELSE
            DEGREES(ACOS(SIN(RADIANS(`p_latitude`)) * SIN(RADIANS('. $lat1 .')) +COS(RADIANS(`lat`)) * COS(RADIANS('. $lat1 .')) * COS(RADIANS(`p_longtitude`-'. $lang1 .'))))* 69.09
        END as distance
    FROM `posts`
    ORDER BY distance desc';
    $resd = $con->query($query);
       while($row_ratessada= $resd->fetch()){
                    $post_rate= $row_ratessada['post_title'];
           echo "this is the title"." ".$post_rate;
       }  
    } 
 
     
    