Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $bedRange = "";
- $propertyType = "";
- $priceRange = "";
- $sourceLong = $_GET['srcLong'];
- $sourceLat = $_GET['srcLat'];
- $searchRange = $_GET['searchRadius'];
- if (isset($_GET['beds_min'])) {
- $bedRange = " and bedrooms between " . $_GET['beds_min'] . " and " . $_GET['beds_max'];
- }
- if (isset($_GET['property_type_id'])) {
- $propertyType = " and property_type_id = " . $_GET['property_type_id'];
- }
- if (isset($_GET['price_min'])) {
- $priceRange = " and price >= " . $_GET['price_min'] . " and price < " . $_GET['price_max'];
- }
- $searchLimit = "";
- $responseMessage = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><response>";
- $db = pg_connect("host=db1 port=5432 dbname=mls user=postgres password=choap5ou");
- if (!$db) {
- echo "Unable to connect to database. Please try again later.";
- exit;
- }
- /* Too many results will cause some serious performance hits. If the user searches a radius of 10 miles, limit to 400 results or so. */
- $queryString = "SELECT property_id,latitude,longitude FROM property WHERE
- (power((69.1*(longitude - " . $sourceLong . ")*cos(" . $sourceLat . "/57.3)),2)+POW((69.1*(latitude-" .
- $sourceLat . ")),2))< (" . $searchRange . "*" . $searchRange . ")" . $bedRange . $propertyType . $priceRange . $searchLimit;
- $cacheString = "FROM property a WHERE (power((69.1*(longitude - " . $sourceLong . ")*cos(" . $sourceLat . "/57.3)),2)+POW((69.1*(latitude-" . $sourceLat . ")),2))< (" . $searchRange . "*" . $searchRange . ")" . $bedRange . $propertyType . $priceRange;
- $result = pg_query($db,$queryString);
- $property_count = pg_num_rows($result);
- /* Get a result ID and put it in the database */
- $fullResults = pg_query($db,"select cache_result_id('" . $cacheString . "')");
- $fullRow = pg_fetch_row($fullResults);
- $result_id = $fullRow[0];
- /* update the result ID with the sql so we can save this query */
- $cacheresult = pg_query($db,"update result set query = 'a.property_id " . $cacheString . "' where result_id = " . $result_id);
- $mapCount = 1;
- while (($row = pg_fetch_array($result)) && ($mapCount <= 200)) {
- $responseMessage .= '<property id="' . $row['property_id'] . '" result_id="' . $result_id . '" count="' . $property_count . '">';
- $responseMessage .= '<latitude>' . $row['latitude'] . '</latitude>';
- $responseMessage .= '<longitude>' . $row['longitude'] . '</longitude>';
- $responseMessage .= '</property>';
- $mapCount++;
- }
- $responseMessage .= '</response>';
- /* Build entry in result_cache */
- echo $responseMessage;
- pg_close($db);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement