%@LANGUAGE="VBSCRIPT"%>
<% Option Explicit %>
<%
' Declare variables
Dim proptype, minprice, maxprice, minbeds, minbaths, location, location2, zipcode, minsqft
Dim nhood_query
Dim pagenum, pagesize, totalmatches, actualNumberShown
Dim sortbyclause, revsortbyclause
Dim sortby1, sortby2, sortby3
Dim sortby1dir, sortby2dir, sortby3dir
Dim count_SQL, homes_SQL
Dim rs_homes
Dim rs_homes_first, rs_homes_last
Dim onLastPage
Dim tempURL, firstURL, prevURL, nextURL, lastURL, showURL
Dim index
'
' Fetch form variables
'
' Search variables
proptype = "M"
minprice = "0"
If len(Request.QueryString("minprice")) > 0 Then
minprice = Request.QueryString("minprice")
End If
maxprice = "99999999"
If len(Request.QueryString("maxprice")) > 0 Then
maxprice = Request.QueryString("maxprice")
End If
minbeds = "0"
If len(Request.QueryString("minbeds")) > 0 Then
minbeds = Request.QueryString("minbeds")
End If
minbaths = "0"
If len(Request.QueryString("minbaths")) > 0 Then
minbaths = Request.QueryString("minbaths")
End If
location = ""
location = Request.QueryString("location")
' /////////////////////////// Added by Markus
If Request.QueryString("location2") <> "" then
location = Request.QueryString("location2")
End If
' /////////////////////////// End Added
zipcode = ""
zipcode = Request.QueryString("zipcode")
minsqft = "0"
If len(Request.QueryString("minsqft")) > 0 Then
minsqft = Request.QueryString("minsqft")
End If
' Sorting Variables
sortby1 = "SALE_PRICE"
If len(Request.QueryString("sortby1")) > 0 Then
sortby1 = Request.QueryString("sortby1")
End If
sortby2 = "None"
If len(Request.QueryString("sortby2")) > 0 Then
sortby2 = Request.QueryString("sortby2")
End If
sortby3 = "None"
If len(Request.QueryString("sortby3")) > 0 Then
sortby3 = Request.QueryString("sortby3")
End If
sortby1dir = "DESC"
If len(Request.QueryString("sortby1dir")) > 0 Then
sortby1dir = Request.QueryString("sortby1dir")
End If
sortby2dir = "DESC"
If len(Request.QueryString("sortby2dir")) > 0 Then
sortby2dir = Request.QueryString("sortby2dir")
End If
sortby3dir = "DESC"
If len(Request.QueryString("sortby3dir")) > 0 Then
sortby3dir = Request.QueryString("sortby3dir")
End If
' Paging variables
totalmatches = -1
If len(Request.QueryString("totalmatches")) > 0 Then
totalmatches = CInt(Request.QueryString("totalmatches"))
End If
pagenum = 1
If len(Request.QueryString("page")) > 0 Then
pagenum = CInt(Request.QueryString("page"))
End If
pagesize = 30
If len(Request.QueryString("pagesize")) > 0 Then
pagesize = CInt(Request.QueryString("pagesize"))
End If
'
' Get total number of matches to the search - WHERE MLS_ID = 'sarasota' AND
'
count_SQL = "SELECT COUNT(SALE_PRICE) AS num FROM dbo.SKY_idx_property " & _
"WHERE PROPERTY_TYPE_CODE = '" & proptype & "' " & _
"AND (SALE_PRICE BETWEEN '" & minprice & "' AND '" & maxprice & "') " & _
"AND CAST(BEDROOMS as int) >= '" & minbeds & "' " & _
"AND CAST(BATHS_TOTAL as real) >= '" & minbaths & "' " & _
"AND (CAST(BUILDING_SQUARE_FOOTAGE as int) >= '" & minsqft & "') "
' is this a streetsearch?
If Request.QueryString("street") <> "" Then
count_SQL = "SELECT COUNT(SALE_PRICE) AS num FROM dbo.SKY_idx_property " &_
"WHERE STREET_NAME LIKE '%" & Request.QueryString("street") & "%' "
If proptype <> "" then count_SQL = count_SQL & "AND PROPERTY_TYPE_CODE = '" & proptype & "' "
count_SQL = count_SQL & "AND (SALE_PRICE BETWEEN '" & minprice & "' AND '" & maxprice & "') " & _
"AND CAST(BEDROOMS as int) >= '" & minbeds & "' " & _
"AND CAST(BATHS_TOTAL as int) >= '" & minbaths & "' " & _
"AND (CAST(BUILDING_SQUARE_FOOTAGE as int) >= '" & minsqft & "') "
End If
Dim nhood_name
If zipcode="" AND location<>"" Then
Dim location_SQL : location_SQL = "SELECT nhood_query, nhood_name FROM dbo.SKY_neighborhoods WHERE nhood_id = '" & location & "'"
Dim rs_location
Set rs_location = Server.CreateObject("ADODB.Recordset")
rs_location.ActiveConnection = MM_conn_skyweblix_STRING
rs_location.Source = location_SQL
rs_location.LockType = 1
rs_location.Open()
rs_location.MoveFirst()
nhood_query = rs_location.Fields.Item("nhood_query")
nhood_name = rs_location.Fields.Item("nhood_name")
rs_location.Close()
Set rs_location = Nothing
count_SQL = count_SQL & "AND (" & nhood_query & ") "
ElseIf zipcode<>"" Then
count_SQL = count_SQL & "AND ZIP_CODE LIKE '%" & zipcode & "%' "
End If
'
' If first time showing results, need to calculate total number of matches
'
If totalmatches = -1 Then
Dim rs_count
Set rs_count = Server.CreateObject("ADODB.Recordset")
rs_count.ActiveConnection = MM_conn_skyweblix_STRING
rs_count.Source = count_SQL
rs_count.LockType = 1
rs_count.Open()
rs_count.MoveFirst()
totalmatches = rs_count.Fields.Item("num")
rs_count.Close()
Set rs_count = Nothing
End If
If totalmatches > 0 Then
'
' Validate the page number, adjusting if necessary
'
If ((pagenum-1)*pagesize)+1 > totalmatches Then
If totalmatches Mod pagesize = 0 Then
pagenum = (totalmatches/pagesize)
Else
pagenum = Round((totalmatches/pagesize) + 0.5)
End If
Elseif pagenum < 1 Then
pagenum = 1
End If
'
' Set the first and last displayed record stats
'
rs_homes_first = ((pagenum-1)*pagesize)+1
rs_homes_last = rs_homes_first + pagesize - 1
actualNumberShown = pagesize
onLastPage = false
If rs_homes_last >= totalmatches Then
actualNumberShown = pagesize - (rs_homes_last-totalmatches)
rs_homes_last = totalmatches
onLastPage = true
End If
' Setup ORER BY clauses
sortbyclause = sortby1 & " " & sortby1dir
If sortby1dir = "ASC" Then
revsortbyclause = "SKYLISTING ASC, " & sortby1 & " DESC"
Else
revsortbyclause = "SKYLISTING ASC, " & sortby1 & " ASC"
End If
If sortby2 <> "None" AND sortby2 <> sortby1 Then
sortbyclause = sortbyclause & ", " & sortby2 & " " & sortby2dir
If sortby2dir = "ASC" Then
revsortbyclause = revsortbyclause & ", " & sortby2 & " DESC"
Else
revsortbyclause = revsortbyclause & ", " & sortby2 & " ASC"
End If
End If
If sortby3 <> "None" AND sortby3 <> sortby1 AND sortby3 <> sortby2 Then
sortbyclause = sortbyclause & ", " & sortby3 & " " & sortby3dir
If sortby3dir = "ASC" Then
revsortbyclause = revsortbyclause & ", " & sortby3 & " DESC"
Else
revsortbyclause = revsortbyclause & ", " & sortby3 & " ASC"
End If
End If
'
' Fetch the current page of results - insert after where - MLS_ID = 'sarasota' AND
'
homes_SQL = _
"SELECT * FROM (" & _
" SELECT TOP " & actualNumberShown & " * FROM (" & _
" SELECT TOP " & (pagenum*pagesize) & " " & _
" CAST(BUILDING_SQUARE_FOOTAGE as int) as BUILDING_SQFT, CAST(BEDROOMS as int) as NUM_BEDROOMS, " & _
" CAST(BATHS_TOTAL as real) AS NUM_BATHS_TOTAL, SKYLISTING, " & _
" LONGITUDE, LATITUDE, BEDROOMS, PHOTO_IND, BATHS_TOTAL, SALE_PRICE, PROPERTY_TYPE_CODE, " & _
" CITY, COUNTY, SUBDIVISION, LOT_SQUARE_FOOTAGE_LAND, BUILDING_SQUARE_FOOTAGE, ZIP_CODE, MLS_ID, TLN_FIRM_ID, STREET_NUMBER, " & _
" STREET_NAME, STREET_TYPE, STREET_DIRECTION, MLS_LISTING_ID, REMARKS " & _
" FROM dbo.SKY_idx_property " & _
" WHERE PROPERTY_TYPE_CODE = '" & proptype & "' " & _
" AND (SALE_PRICE BETWEEN '" & minprice & "' AND '" & maxprice & "') " & _
" AND CAST(BEDROOMS as int) >= '" & minbeds & "' " & _
" AND CAST(BATHS_TOTAL as real) >= '" & minbaths & "' " & _
" AND (CAST(BUILDING_SQUARE_FOOTAGE as int) >= '" & minsqft & "') "
If Request.QueryString("street") <> "" Then
homes_SQL = "SELECT * FROM (" & _
" SELECT TOP " & actualNumberShown & " * FROM (" & _
" SELECT TOP " & (pagenum*pagesize) & " " & _
" CAST(BUILDING_SQUARE_FOOTAGE as int) as BUILDING_SQFT, CAST(BEDROOMS as int) as NUM_BEDROOMS, " & _
" CAST(BATHS_TOTAL as real) AS NUM_BATHS_TOTAL, SKYLISTING, " & _
" LONGITUDE, LATITUDE, BEDROOMS, PHOTO_IND, BATHS_TOTAL, SALE_PRICE, PROPERTY_TYPE_CODE, " & _
" CITY, COUNTY, SUBDIVISION, LOT_SQUARE_FOOTAGE_LAND, BUILDING_SQUARE_FOOTAGE, ZIP_CODE, MLS_ID, TLN_FIRM_ID, STREET_NUMBER, " & _
" STREET_NAME, STREET_TYPE, STREET_DIRECTION, MLS_LISTING_ID, REMARKS " & _
" FROM dbo.SKY_idx_property " & _
" WHERE STREET_NAME LIKE '%" & Request.QueryString("street") & "%' "
If proptype <> "" then homes_SQL = homes_SQL & "AND PROPERTY_TYPE_CODE = '" & proptype & "' "
homes_SQL = homes_SQL & "AND (SALE_PRICE BETWEEN '" & minprice & "' AND '" & maxprice & "') " & _
"AND CAST(BEDROOMS as real) >= '" & minbeds & "' " & _
"AND CAST(BATHS_TOTAL as int) >= '" & minbaths & "' " & _
"AND (CAST(BUILDING_SQUARE_FOOTAGE as int) >= '" & minsqft & "') "
End If
If zipcode="" AND location<>"" Then
homes_SQL = homes_SQL & "AND (" & nhood_query & ") "
ElseIf zipcode<>"" Then
homes_SQL = homes_SQL & "AND ZIP_CODE LIKE '%" & zipcode & "%' "
End If
homes_SQL = homes_SQL & _
" ORDER BY " & sortbyclause & ") AS T1 " & _
" ORDER BY " & revsortbyclause & ") as T2 " & _
"ORDER BY " & sortbyclause
'
' Retrieve the actual data to be shown
'
Set rs_homes = Server.CreateObject("ADODB.Recordset")
rs_homes.ActiveConnection = MM_conn_skyweblix_STRING
rs_homes.Source = homes_SQL
Session("query") = homes_SQL
rs_homes.CursorType = 2
rs_homes.CursorLocation = 2
rs_homes.LockType = 1
rs_homes.Open()
'
' Set URLs for previous/next page links
'
tempURL = Request.ServerVariables("URL") & "?"
If len(Request.QueryString("street")) > 0 Then tempURL = tempURL & "street=" & Server.URLEncode(Request.QueryString("street")) & "&"
If proptype <> "" then tempURL = tempURL & "proptype=" & Server.URLEncode(proptype)
If len(Request.QueryString("minprice")) > 0 Then tempURL = tempURL & "&minprice=" & Server.URLEncode(minprice)
If len(Request.QueryString("maxprice")) > 0 Then tempURL = tempURL & "&maxprice=" & Server.URLEncode(maxprice)
If len(Request.QueryString("minbeds")) > 0 Then tempURL = tempURL & "&minbeds=" & Server.URLEncode(minbeds)
If len(Request.QueryString("minbaths")) > 0 Then tempURL = tempURL & "&minbaths=" & Server.URLEncode(minbaths)
If len(Request.QueryString("totalmatches")) > 0 Then tempURL = tempURL & "&totalmatches=" & Server.URLEncode(totalmatches)
If location <> "" then tempURL = tempURL & "&location=" & Server.URLEncode(location)
If len(Request.QueryString("minsqft")) > 0 Then tempURL = tempURL & "&minsqft=" & Server.URLEncode(minsqft)
If zipcode <> "" then tempURL = tempURL & "&zipcode=" & Server.URLEncode(zipcode)
If len(Request.QueryString("sortby1")) > 0 Then tempURL = tempURL & "&sortby1=" & Server.URLEncode(sortby1)
If len(Request.QueryString("sortby1dir")) > 0 Then tempURL = tempURL & "&sortby1dir=" & Server.URLEncode(sortby1dir)
If len(Request.QueryString("sortby2")) > 0 Then tempURL = tempURL & "&sortby2=" & Server.URLEncode(sortby2)
If len(Request.QueryString("sortby2dir")) > 0 Then tempURL = tempURL & "&sortby2dir=" & Server.URLEncode(sortby2dir)
If len(Request.QueryString("sortby3")) > 0 Then tempURL = tempURL & "&sortby3=" & Server.URLEncode(sortby3)
If len(Request.QueryString("sortby3dir")) > 0 Then tempURL = tempURL & "&sortby3dir=" & Server.URLEncode(sortby3dir)
prevURL = tempURL & "&page=" & Server.URLEncode(pagenum-1) & "&pagesize=" & Server.URLEncode(pagesize)
nextURL = tempURL & "&page=" & Server.URLEncode(pagenum+1) & "&pagesize=" & Server.URLEncode(pagesize)
showURL = tempURL & "&page=" & Server.URLEncode(pagenum)
firstURL = tempURL & "&page=1"
If totalmatches Mod pagesize = 0 Then
lastURL = tempURL & "&page=" & (totalmatches/pagesize)
Else
lastURL = tempURL & "&page=" & Round((totalmatches/pagesize) + 0.5)
End If
' this is where we determine the type of property for the URL
Dim proptypeget, proptype2
proptypeget = "S"
If rs_homes.Fields.Item("PROPERTY_TYPE_CODE").Value <> "" then
proptypeget = (rs_homes.Fields.Item("PROPERTY_TYPE_CODE").Value)
End If
Select Case proptypeget
Case "D"
proptype2 = "homes"
Case "V"
proptype2 = "vacant-land"
Case "M"
proptype2 = "condos"
Case "S"
proptype2 = "homes"
End Select
' END this is where we determine the type of property for the URL
End If
%>
<%If nhood_name <> "" then %> <%=nhood_name%> Condos for Sale<%else%>Condo Search Results<%end if%>
See all condos for sale in <%=nhood_name%>, Florida. Active condominium listings updated daily from the Sarasota MLS<%else%>Home Search Results<%End If%>." />
<%If nhood_name <> "" then %><%=nhood_name%> Condos for Sale<%else%>Condo Search Results<%end if%>
Condos <%If nhood_name <> "" then %>in <%=nhood_name%> Currently For Sale<%else%>Matching Your Search <%end if%>
<%
'
' Show no results if so...
'
If totalmatches = 0 Then
%>
<%=FormatCurrency((rs_homes.Fields.Item("SALE_PRICE").Value),0)%>
<%=(rs_homes.Fields.Item("CITY").Value)%>
<% If ((rs_homes.Fields.Item("BEDROOMS").Value <> "" AND rs_homes.Fields.Item("BEDROOMS").Value <> "0") AND (rs_homes.Fields.Item("PROPERTY_TYPE_CODE").Value <> "V")) Then
%> <%=(rs_homes.Fields.Item("BEDROOMS").Value)%> Bed, <%
End If
If ((rs_homes.Fields.Item("BATHS_TOTAL").Value <> "" AND rs_homes.Fields.Item("BATHS_TOTAL").Value <> "0") AND (rs_homes.Fields.Item("PROPERTY_TYPE_CODE").Value <> "V")) Then
%> <%=(rs_homes.Fields.Item("BATHS_TOTAL").Value)%> Bath <%
End If
%> .htm" class="xs">Condo
Details