|
<%
DIM SQL1, SQL2, sql_list, objRS1, objRS2, ziplist
DIM mydistance, connection, totaldealers, dealers, total_distance,total_dist,shops
IF Request.QueryString("Search") <> "" Then
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=D:\inetpub\virtual\bridgetsoferin\WWWROOT\CGI-BIN\Distance\us_zip.mdb"
'check if the postal code submitted is in valid format
IF IsNumeric(left(Request.QueryString("Search"),5)) = false then
Response.Write("Please enter a properly formed postal code.")
Else
'grab the location of the user's submitted postal code
SQL1 = "SELECT * From US_ZIP where zip= '" & Request.QueryString("Search") & "'"
Set objRS1 = Connection.Execute(SQL1)
'get a list of locations for all of our dealers by joining on ZIP
'SQL_list = "SELECT Latitude, Longitude, address, city, state, zip, email, directions "
SQL_list = "SELECT * From Dealers INNER JOIN US_ZIP ON Dealers.ZIP = US_ZIP.ZIP order by US_ZIP.ZIP"
'Response.Write(SQL_list)
'Response.End
set objRS2 = Connection.Execute(SQL_list)
'Set distance = Server.CreateObject("calculate.dist")
totaldealers = 0
Do while not objRS2.eof
IF Not objRS1.EOF Then
'compare the submitted location with each item in our dealer list and return the distance
total_distance = round(distance(objRS1("Latitude"),objRS1("Longitude"),objRS2("Latitude"),objRS2("Longitude"),"miles"),1)
'total_dist = round(total_distance,1)
Else
Response.Write("Your postal code was not found in our current table.")
Response.End
End IF
'=======Change distance here=========='
If Request("distance") > 20000 Then
Response.Write("Please enter a smaller distance.")
Response.End
End IF
'=======Change distance here=========='
IF total_distance =< cInt(Request("distance")) Then
shops = shops & " |