AllExperts > Experts 
Search      

Active Server Pages Programming (ASP)

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Chris
Expertise
I can answer pretty much any question relating to VB.NET and its use in a Windows environment. I can also handle most questions using C#. I specialize in ASP.NET web development and MSSQL database access, but have some stale knowledge of the old ASP - I'd prefer to avoid questions about it.

Experience
I have over 5 years of industry experience using VB.NET and other .NET technologies for web and database development.

Education/Credentials
I have some college education, but does it really matter in this field of work?

 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > It displays the Equal ones but how about the larger than?

Topic: Active Server Pages Programming (ASP)



Expert: Chris
Date: 10/15/2007
Subject: It displays the Equal ones but how about the larger than?

Question
Hello there; This below search results code works but I have 1 propblem. When I select 3 bedrooms option on the form, result page gives me only the 3 bedrooms items from the Access database. But i want it work to do this: When i select 3 bedrooms option on the form the result page should give me all 3 beds and 2 beds and 1 beds. I mean 3 bedrooms and all below ones. Can you tell me how can i do that and where to modify? Thank you very much.
Access database has a column called T_Bedrooms and has number field and it just has values :1 or 2 or 3 or 4 or 5 or 6. This column values should be numbers or text?

+++++   1 st PAGE: SEARCH FORM   +++++++

<form method="POST" action="search/results.asp">
<SELECT name="T_Bedrooms" id="T_Bedrooms">
<option value="%">All</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</SELECT>
<input type=submit value=Submit>
</form>


+++++   2 st PAGE: RESULTS   +++++++

<!--#include file="inc_bagla.asp"-->
<%
   Dim sort_id     'The variable to sort data
   Dim intPage     'The variable to hold current page number
   Dim sSQL        'The variable to hold the SQL Statement
   Dim intPageCount    'The var to hold total page count
   Dim intRecordCount  'The var to hold total records count
   Dim intFinish       'The var to hold the last page count
   Dim intStart        'The var to hold the first page count
   Dim intRecord
   Dim sort_type
   Dim new_sort_type
  '-------Getting Info of page Number-------------
  sort_id=Request("sortid")
  If Request.QueryString("NAV") = "" Then
      intPage = 1
  Else
      intPage = Request.QueryString("NAV")
  End If
  
  sort_type = Request("sorttype")
  dim sSortSymbol
  dim sTempSymbol
     dim current_sort
  if ucase(sort_type)="DESC" then
      sort_type="DESC"
      new_sort_type="ASC"
      sTempSymbol="[<FONT FACE=wingdings>ê</font>]"
  else
      sort_type="ASC"
      new_sort_type="DESC"
      sTempSymbol="[<FONT FACE=wingdings>é</font>]"
  end if

  dim sWhereCondition %>

<%'-------Getting T_Bedrooms
dim T_Bedrooms
T_Bedrooms =Request("T_Bedrooms")%>
<%if trim(T_Bedrooms) <>"" then
  sWhereCondition=sWhereCondition & " AND [T_Bedrooms] like '%" & T_Bedrooms & "%'"
end if%>


<%'-------Getting T_Type
dim T_Type
T_Type=Request("T_Type")%>
<%if trim(T_Type) <>"" then
  sWhereCondition=sWhereCondition & " AND [T_Type] like '%" & T_Type & "%'"
end if%>


<%'-------Getting T_Price
dim T_Price
T_Price=Request("T_Price")%>
<%if trim(T_Price) <>"" then
  sWhereCondition=sWhereCondition & " AND [T_Price] like '%" & T_Price & "%'"
end if%>


<!-- START AVAILABLE NUMBER -->
<%if sWhereCondition="" then
  sSQL="SELECT * FROM [details]"
else
       sWhereCondition = Right(sWhereCondition, Len(sWhereCondition) - 4)
  sSQL="SELECT * FROM [details]" & " WHERE " & sWhereCondition
end if

if sort_id<>"" then
  sSQL=sSQL & " ORDER BY [" & sort_id & "] " & sort_type
end if
%>

  <%dim objRst     'The Recordset object
  Set objRst = Server.CreateObject("ADODB.Recordset")
  objRst.CursorLocation = 3   'adUseClient
  objRst.CursorType = 3       'adOpenStatic
   objRst.ActiveConnection = con
   ' Open the recordset.
   objRst.Open sSql
   'Now Prepend the sData String
   objRst.PageSize = 10
   ' The cachesize property sets the number of records that will be cached
   ' locally in memory.
   objRst.CacheSize = objRst.PageSize
   intPageCount = objRst.PageCount
   intRecordCount = objRst.RecordCount
   If CInt(intPage) > CInt(intPageCount) Then intPage = intPageCount
   If CInt(intPage) <= 0 Then intPage = 1
   ' Make sure that the recordset is not empty.  If it is not, then set the
   ' AbsolutePage property and populate the intStart and the intFinish variables.
   If intRecordCount > 0 Then
       objRst.AbsolutePage = intPage
       intStart = objRst.AbsolutePosition
       If CInt(intPage) = CInt(intPageCount) Then
           intFinish = intRecordCount
       Else
           intFinish = intStart + (objRst.PageSize - 1)
       End If
End If%>
<!-- END CODE1 -->



<%=objRst("T_Bedrooms").Value%>

Answer
You could change the data type of the T_Bedrooms field in the database to be an integer instead of a string, then you could query WHERE T_Bedrooms > SomeNumber.  Or, you could do a for loop and construct a series of OR's for your WHERE query... for example:

If (Request("T_Bedrooms") <> "") Then
 Dim intMinBedroomsToFind As Integer = Request("T_Bedrooms")
 sWhereCondition = sWhereCondition & " AND ("
 For iFindBedrooms As Integer = 1 To intMinBedroomsToFind
   If (i > 1) Then sWhereCondition = sWhereCondition & " OR "
   sWhereCondition = sWhereCondition & " AND [T_Bedrooms] LIKE %" & i & "% "
 Next
 sWhereCondition = sWhereCondition & ")"
End If


Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.