Sunset at Oak Island, North Carolina

Spider Web Woman Designs

How to filter a database query using two drop down lists

SUMMARY

FrontPage® 2000 and 2002 enable you to create a database query that results in a list that displays all of the records in a particular field. This article describes the steps you can use to limit the results of another database query.

MORE INFORMATION

This article assumes that you have already imported your Access database into your web, and that FrontPage has created the fpdb folder, put the database in that folder, and created the global.asa file and the database connection. Please review How to create a FrontPage Database Connection for more information. For this tutorial, we will be using a database called autos.mdb that you can download from this site. We are going to name the Database connection "myautos". We are going to use the "cars" table.

To filter a database query using 2 dropdown lists, follow these steps:

  1. Create a new page and save it as drop1.asp.
  2. On the Insert menu, point to Form, and select Form.
  3. Delete the Reset button.
  4. Position your cursor within the form, to the left of the Submit button.
  5. On the Insert menu, point to Database, and select Results.
  6. In step 1 of the wizard, select your database connection (myautos). Click Next.
  7. In step 2 of the wizard, select your record source (cars). Click Next.
  8. In step 3 of the wizard, select Edit List and remove all of the fields, except the first field that will be used to query the database. We are going to use "company" for the first query. Click OK. Click Next.
  9. In step 4 of the wizard, click to select Drop-Down List from the list of formatting options. Click Next.
  10. In step 5 of the wizard, click Finish.
  11. Save the page and Preview in Browser. You will notice that each "company" is displayed in the dropdown list more than once. To eliminate the duplicates, in FrontPage, switch to HTML view, and find the SQL for the dropdown, in the gray-colored code. It should look like this: s-sql="SELECT * FROM cars" and change it s-sql="SELECT DISTINCT company FROM cars". Save the changes while still in HTML view. You will notice that once you've saved your changes they are also made to the maroon colored code - that is by design. The maroon colored code should never be touched; it's generated by the gray code at save time.
  12. Preview in Browser again and now you will see each company only appear once.
  13. In FrontPage, in Normal View, right-click on the form, select Form Properties, Send to other: Custom ISAPI, NSAPI, CGI, or ASP Script. Click on Options, and set the Action to: drop2.asp. Click OK twice. You have now set the form in drop1 to post to drop2 when the user hits the Submit button.
  14. Save the page.
  15. Save the page (Save As) as drop2.asp.
  16. With drop2.asp open, in Normal View, position your cursor in between the Database Results Region (see Exhibit 1) and the Submit button.
  17. On the Insert menu, point to Database, and select Results.
  18. In step 1 of the wizard, select your database connection (myautos). Click Next.
  19. In step 2 of the wizard, select your record source (cars). Click Next.
  20. In step 3 of the wizard, select Edit List and remove all of the fields, except the field that will be used to query the database in the second dropdown. We are going to use "model" for the second query. Click OK. Click Next.
  21. In step 4 of the wizard, click to select Drop-Down List from the list of formatting options. Click Next.
  22. In step 5 of the wizard, click Finish.
  23. Right-click on the form, select Form Properties, Send to other: Custom ISAPI, NSAPI, CGI, or ASP Script. Click on Options, and set the Action to: drop3.asp. Click OK. You have now set the form in drop2 to post to drop3 when the user hits the Submit button.
  24. Switch to HTML view and find the first SQL statement in the gray colored code - it will look like this: s-sql="SELECT DISTINCT company FROM cars" change it to s-sql="SELECT DISTINCT company FROM cars WHERE (company = '::company::')".
  25. While still in HTML view, find the second SQL statement in the gray colored code - it will look like this: s-sql="SELECT * FROM cars" change it to s-sql="SELECT DISTINCT model FROM cars WHERE (company = '::company::')"
  26. Save the changes while still in HTML view. Close drop2.asp
  27. Create a new page and save it as drop3.asp
  28. On the Insert menu, point to Database, and select Results.
  29. In step 1 of the wizard, select your database connection (myautos). Click Next.
  30. In step 2 of the wizard, select your record source (cars). Click Next.
  31. In step 3 of the wizard, click More Options, Criteria, and click Add.
  32. Verify that the Field Names (company and model) and the Value entries are the same as the ones you are using for your query. Make sure the "Use this search form field" check box is selected. Click OK twice.
  33. In the More Options dialog box, click Defaults. Click Edit. Add default values for both fields that match the field type. In this case, because the fields are text fields, you can enter xxxxx. For number fields, the default value could be all 0's (zeroes) or all 9's.
  34. Click OK three times.
  35. In step 4, choose to return the result to a table.
  36. In step 5, make sure the Add Search Form check box is not selected. Click Finish.
  37. Save the page.
  38. Open drop1.asp and Preview in Browser.

 



Email UsWe're on Google+LinkedIn ProfileFollow us on TwitterLike Us on Facebook!