469,329 Members | 1,372 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Asp + Dreamweaver - I cannot filter my dispalyed data from DB for a drop down list

In Dreaweaver I cannot filter my database results to display only specific data that is retrieved from mulptile drop down list on my search page. The drop down list selections are posted to my display page by GET. How do i write my sql code so to only display info where TOWN = "Town selected from list" AND BEDS ="No of Beds selected from list

My search page form is below

Expand|Select|Wrap|Line Numbers
  1. <form action="tsearchresults.asp" method="get" name="townSearchForm" id="townSearchForm">
  2.                    <select name="varBeds" id="varBeds">
  3.                                 <option value="%" >All</option>
  4.                                 <option value="1 Bedroom" >1 Bedroom</option>
  5.                                 <option value="2 Bedrooms" >2 Bedrooms</option>
  6.                                 <option value="3 Bedrooms" >3 Bedrooms</option>
  7.                                 <option value="4 Bedrooms" >4 Bedrooms</option>
  8.                                 <option value="5 Bedrooms" >5 Bedrooms</option>
  9.                                 </select>
  10.  
  11.  
  12.                    <select name="varTown" id="varTown">
  13.                               <option value="%">All</option>
  14.                                                         <option value="Augher">Augher</option>
  15.  
  16.                 <option value="Coalisland">Coalisland</option>
  17.                 <option value="Cookstown">Cookstown</option>
  18.                 <option value="Donaghmore">Donaghmore</option>
  19.                  <option value="Dromore">Dromore</option>
  20.  
  21.  
  22.                                                          </select>
  23.  
  24.         <input type="submit" name="Findhouse" id="Findhouse" value="Search" />
  25.  
  26.  
  27.  
  28.                 </form>
  29.  
When the page tsearchresults.asp (below) is displayed the url displays - http://localhost/tyrone/tsearchresults.asp?varBeds=%25&varTown=Augher&Find house=Search
- hence just the fiter of town for town = Augher. But all towns are displayed

I select Bindings and Recordset in dreamweaver on tserachresults page and in the advanced section -
I select all records from my table but cant figure out how to write my where statement to select the Town and Number of beds as passed from my search page


My variables, default values and Run time values are as below - am i refering correctly to my values from the form
varTown % Request.QueryString("Town")
varBeds % Request.QueryString("Beds")
where Town and Beds are records in my database.

The asp code for this is below


Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim Recordset1__varBeds
  3. Recordset1__varBeds = "%"
  4. If (Request.QueryString("Beds") <> "") Then 
  5.   Recordset1__varBeds = Request.QueryString("Beds")
  6. End If
  7. %>
  8. <%
  9. Dim Recordset1__varTown
  10. Recordset1__varTown = "%"
  11. If (Request.QueryString("Town") <> "") Then 
  12.   Recordset1__varTown = Request.QueryString("Town")
  13. End If
  14. %>
  15.  
  16.  
  17. <%
  18. Dim Recordset1
  19. Dim Recordset1_numRows
  20.  
  21. Set Recordset1 = Server.CreateObject("ADODB.Recordset")
  22. Recordset1.ActiveConnection = MM_connTyrone_STRING
  23. Recordset1.Source = "SELECT DateAvailable, Address, Town, Postcode, Description1,  Let, PropertyType, Beds, Price, ID, DatePosted, Description2  FROM HouseDetails  WHERE Beds like '" + Replace(Recordset1__varBeds, "'", "''") + "' AND Town like '" + Replace(Recordset1__varTown, "'", "''") + "'"
  24. Recordset1.CursorType = 0
  25. Recordset1.CursorLocation = 2
  26. Recordset1.LockType = 1
  27. Recordset1.Open()
  28.  
  29. Recordset1_numRows = 0
  30. %>
  31.  
  32.  
  33.  
  34. While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
  35.  
  36.  
  37. <%=(Recordset1.Fields.Item("Beds").Value)%> <%=(Recordset1.Fields.Item("Town").Value)%>         
  38.           <td valign="top" class="PropertyHeading"><%=(Recordset1.Fields.Item("Address").Value)%>

All values are displayed and not just search results


Any Help would be VERY MUCH APPRECIATED
Aug 2 '07 #1
2 2923
ilearneditonline
130 Expert 100+
When processing a form, your Request.QueryString or Request.Post should reference the name of the form field, not the name of the field in the database.

So where you are referencing Request.QueryString("Beds"), you will never find that in your querystring, because you dropdown box is named varBeds.

Try replacing this section....
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim Recordset1__varBeds
  3. Recordset1__varBeds = "%"
  4. If (Request.QueryString("Beds") <> "") Then
  5. Recordset1__varBeds = Request.QueryString("Beds")
  6. End If
  7. %>
  8. <%
  9. Dim Recordset1__varTown
  10. Recordset1__varTown = "%"
  11. If (Request.QueryString("Town") <> "") Then
  12. Recordset1__varTown = Request.QueryString("Town")
  13. End If
  14. %>
With...
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim Recordset1__varBeds
  3. Recordset1__varBeds = "%"
  4. If (Request.QueryString("varBeds") <> "") Then
  5. Recordset1__varBeds = Request.QueryString("varBeds")
  6. End If
  7. %>
  8. <%
  9. Dim Recordset1__varTown
  10. Recordset1__varTown = "%"
  11. If (Request.QueryString("varTown") <> "") Then
  12. Recordset1__varTown = Request.QueryString("varTown")
  13. End If
  14. %>
Aug 3 '07 #2
jhardman
3,406 Expert 2GB
When processing a form, your Request.QueryString or Request.Post should reference the name of the form field, not the name of the field in the database.

So where you are referencing Request.QueryString("Beds"), you will never find that in your querystring, because you dropdown box is named varBeds.
of course i always find it convenient to use the same name in the first place...

Jared
Aug 3 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Dan | last post: by
2 posts views Thread by ramesh | last post: by
5 posts views Thread by Vigneshwar Pilli via DotNetMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.