An example on a simple page that does the calculations on the fly (in php) is here:
First generate a db in mysql called "uszipcodes" then run the sql script linked above.
code:
<?php
////////////////////// DB-Access /////////////////////////
/*Generates the connection with the database and returns a
valid connection for the one calling. */
function hookUpDb(){
Global $connection;
$host = 'localhost';
$user = '';
$password = '';
$db = 'uszipcodes';
if(mysql_connect($host,$user,$password)){
$connection = mysql_connect($host,$user,$password);
mysql_select_db($db,$connection);
return $connection;
}else{
print("<b>Sorry, cannot connect to the database.</b>");
}
}
/////////////////////////////////////////////////////
////////////////////// Generic QueryAskers///////////
/*Use when no returned result is excepted.
returns true or mysql_error. */
function doQuery($sql){
Global $connection;
hookUpDb();
/*Use this when you need to use custom made SQL-queries on the database.
Returns a 2 dimensional array with the result. */
function doQueryResult($sql){
Global $connection;
hookUpDb();
if($sql != ""){
$result = mysql_query($sql,$connection);
$item = array();
while($item = mysql_fetch_array($result)){
$items[] = $item;
}
return $items;
mysql_free_result($result);
} else {
print("Need correctly formed SQL that returns a resultset.");
}
}
/////////////////////////////////////////////
foreach($finalResult as $location){
print("<fieldset><legend>Location within ".$_POST['radius']." miles from ".$userLocation.".</legend>\n");
print("City: ".$location['city']."<br>State: ".$location['state']."<br>zipcode: ".$location['zip']);
print("</fieldset>");
}
}
?>
</body>
</html>
Note that this is only one way of doing it and that it probably will draw a lot of power from the server with a lot of traffic.
In this thread a lot of useful variations on this is discussed: http://www.ozoneasylum.com/21687