Software Downloads

Collins Software
Houston Texas, 713-682-1556 
Providing GIS Web Publishing solutions and GIS Database Migration software utilities
Web Software Development


addresslookup.php

Return CSV of  "X,Y,Address" of nearest address given a unique street Identifier and a house number. There are some 18,000 unique street names for the City of Houston.

<?php
//************************************************************
//                        addresslookup.php
//   Author: Clif Collins
//   Copyright (c) 2005 Clifford L. Collins
//   All rights reserved
//------------------------------------------------------------
//
//   use:
//   http://collinssoftware.com/addresslookup.php?StreetID=5&Number=619
//
//************************************************************

session_start();

?>
<?php
//============================================================
//                       getStreetName
// return street name "Janak Drive" given a unique id "5422"
//============================================================
function getStreetName($database, $id)
{
   $name = "";

   $sql = "select name from street where id = " . $id;
   $rs  = mysql_db_query($database, $sql);
   if (!rs) return '';

   if (mysql_numrows($rs) >= 1)
   {
     if ($data = mysql_fetch_row($rs)) $name = $data[0];
   }

   mysql_free_result($rs);
   return $name;
}
?>

<?php
//===========================================================
//                           main
//===========================================================
  $id = $_GET['StreetID'];
  $num = $_GET['Number'];

  if (empty($id)) die('empty');
  if (empty($num)) $num = 0;
  
  $id = intval($id);
  $num = intval($num);

  if (! is_int($id)) die('not integer');
  if (! is_int($num)) $num = 0;

  $low  = $num - 50;
  $high = $num + 50;

  $BaseSQL = "Select * from bridge where id = " . $id;
  $xNumber = " and Addrno = " . $num;
  $xRange  = " and Addrno >= " . $low . " and Addrno <= " . $high;
  $xGT     = " and Addrno >= " . $num;
  $xLT     = " and Addrno <= " . $num;

  $chandle = mysql_pconnect("localhost", "guest", "")
      or die("Connection Failure to Database");
  session_register("database");
  $database="Street";
  mysql_select_db($database, $chandle) or die ("Database not found = " . $database);

  $street = getStreetName($database, $id);

  $sql1 = $BaseSQL . $xNumber;  // exact match
  $sql2 = $BaseSQL . $xGT;      // an address greater than given
  $sql3 = $BaseSQL;             // any address on street

// -- try 3 different SQL statements until found (or not) --

  $rs = mysql_db_query($database, $sql1);
  if(!$rs or (mysql_numrows($rs) < 1)) $rs = mysql_db_query($database, $sql2);
  if(!$rs or (mysql_numrows($rs) < 1)) $rs = mysql_db_query($database, $sql3);

// --- if found then return x,y,address ----

  if ($rs and mysql_numrows($rs) >= 1)
  {
     $data = mysql_fetch_row($rs);
     $x = $data[1];
     $y = $data[2];
     $num = $data[3];
     echo $x . "," . $y . "," . $num . " " . $street;                    
  }
  mysql_free_result($rs);
  mysql_close($chandle);
?>

 


Copyright © 2008 Collins Software
All Rights Are Reserved