Newbie here need help with PHP MYSQL

hi ppl I am new here hope to find some help around regarding php ok here go currently I having 2 table:

Districts Table

Location Table

from the 2 table I need to do a php coding to compare the value against the 2 table which is the districts.startlat,districts.endlat,districts.startlng and districts.endlng and the location table location.lat and location.lng and return the uname below is the php code I come out with but it just does not look correct at all


<?php
$temp="";
 

 $sqlconnect=mysql_connect("localhost","hyperian_track","gsmtrack");
 if(!$sqlconnect)
  die(mysql_error());
 mysql_select_db("hyperian_track", $sqlconnect);

if($_GET["postal"]))
$postalcode=substr($_GET["postal"],0,2); //will return from 0 position 2 characters
$resultpostal=mysql_query("SELECT startlat,endlat,startlng,endlng FROM districts
WHERE districtno = $postalcode"); //get startlat,endlat,startlng,endlng of location
if($row = mysql_fetch_array($resultpostal))
  {
   $postalno=$row;    // store each record in an array
  }
 
 
$resultname=mysql_query("SELECT uname FROM location,$postalno
 WHERE location.lat < $postalno.startlat AND location.lat > $postalno.endlat AND location.lng < $postalno..startlng
 AND location.lng > $postalno.endlng");
if($row = mysql_fetch_array($resultname))
  {
   $temp[]=$row;
  }
 
  foreach($temp as $key=>$extract)
  $reportname=$reportname.$key."=".$extract."&";

  echo $reportname;
}//end of if loops
 
mysql_close($con);
 
 
 

I want to know if from the statement one I create a variable and store all the sql query inside then I need to compare the stored sql query with the location table to get the uname so is my code correct can I just declare and variable and compare it eg:location.lat > $postalno.endlat