Searching a Database Creating a Form for Users to Search a Database

advertisement
Searching a Database
Creating a Form for Users to
Search a Database
Overview
Searching a Database
To enable users to search a databse, you
begin by creating a form that prompts
users for the field(s) to be searched.
You make the form’s action be a dynamic
Web page, such as an ASP.
On the ASP page, you create a RecordSet
that uses the search form’s data as input;
thus, the Recordset contains the search
results.
As a final touch, you display the RecordSet
onscreen, thereby showing the user the
search results.
Prerequisites
Defining a Database
These instructions assume that you
have already defined a data source
for this Web site.
The data source contains the data
table that your search form will
search.
If you have not defined the data
source, do so following the
instructions provided earlier in the
lesson on data driven Webs.
Step One
Create the Search Page
Use Dreamweaver to open the site in which
you want to create the login form.
Pull down the File menu and choose New to
bring up the New Document dialog.
Select the Dynamic Page category to make
the Dynamic Page options appear.
Select ASP JavaScript and click the
Create button; the new page appears.
Pull down the File menu, choose Save, and
save the file in your site’s local root folder;
in this example, make the filename be
SearchForm.asp.
Step Two
Put a Search Form on the Search Page
Pull down the menu at the left edge of the toolbar and choose
forms; the form tools appear on the toolbar:
Use the Form tools to insert a form and create a search field;
make the name of the field match the name of the
corresponding data field. If you are creating a form to search
the LastName column of the Users table, for example, make
the search field’s name be LastName.
Insert a label to identify the search field onscreen. Type any
instructions you want the user to see.
Insert a submit button and make its text be Search.
Make the form’s action be the dynamic Web page that will
conduct the search and display the results; in this example,
make the action be SearchResults.asp.
Use Dreamweaver to format the form as you wish, then save
the file.
Step Three
Create the Results Page
Pull down the File menu and choose New to
bring up the New Document dialog.
Select the Dynamic Page category to make
the Dynamic Page options appear.
Select ASP JavaScript and click the
Create button; the new page appears.
Pull down the File menu, choose Save, and
save the file in your site’s local root folder;
in this example, make the filename be
SearchResults.asp.
Step Four
Create a Recordset of the Search Results
While you are on the SearchResults.asp page, click
the Bindings tab of the Application window, or pull
down the Window menu and choose Bindings.
Click the plus sign button and choose recordset to
make the recordset dialog appear.
Customize the Name field to suit your application.
In this example, make the Name field say
SearchResults.
Choose the connection that contains the table.
Select the data table containing all of the data.
Select the data fields you want displayed in the
search results; in this example, choose all the data
fields.
Step Four
(continued)
Create a Recordset of the Search Results
Pull down the Filter field and choose the
name of the data column being searched. In
this example, choose LastName:
Step Four
(completed)
Create a Recordset of the Search Results
Pull down the field under the Filter field
and set it to Form Variable; this makes the
search pick up data from the incoming
form.
Make the form variable’s name be the name
of the field on your form. In this example,
the field is: LastName
Click the Test button to test your search
setup.
Click OK to close the Recordset dialog.
Step Five
Display the Recordset of Search Results
Click to position the cursor at the spot on
the page where you want to display the
data.
Pull down the menu at the left edge of the
toolbar and choose Application; the
Application tools appear on the toolbar:
In the Application toolbar, click the
Dynamic Table tool to make the Dynamic
Table dialog appear.
Step Five
(continued)
Display the Recordset of Search Results
Fill out the Dynamic Table Dialog to
make it display the Recordset
containing your search results, then
click OK:
Step Six
Publish and Test the Pages
Save and publish to your Web site
the SearchResults.asp page.
In Dreamweaver, click to position
your cursor anywhere on the
SearchForm.asp page, then press F12
to publish and test it.
When the Search form appears in
your browser, fill out the form and
click the Search button.
Step Seven
Secure the Pages
Troubleshoot any problems until you
get the search working correctly.
If the search form and the search
results are to be viewed only by
authorized users, pull down the
Application toolbar’s User
Authentication menu and choose
Restrict Access to Page. If you have
not yet set up a Login procedure, see
the lesson on the Login Process.
Download