Implementing User Searching Capabilities
Introduction. We
have now developed the major components for our store in terms of
Departments and Products. But it may be the case that a user
doesn't classify their music in the same way as we do, or maybe they
want to move specifically to a location based on some other
information. This is best done by creating searching
capabilities. This will be much less complicated than what we just
did and we will have just one ASP and one stored procedure.
We will develop one stored procedure and one ASP file. While both are decently elaborate, these are all that are required. |
The Stored Procedures. This stored procedure gets the SearchText, High end of acceptable prices and the Low end of acceptable prices from the user. Then it uses these to select from the products everything that meets the criteria. The first file should be called sp_SearchProducts.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connfoxFire, strSQLCreate Set connfoxFire = Server.CreateObject("ADODB.Connection") connfoxFire.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_SearchProducts @SearchText varchar(255), @Low int, @High int AS " & _ "select * from products where (chrProductName like '%' + @SearchText+ '%' or " & _ "txtDescription like '%' + @SearchText + '%') and " & _ "(intPrice >= @low and intPrice <= @High) order by chrProductName" connfoxFire.execute(strSQLCreate) |
Now we need to creatour ASP that will execute this
stored procedure to open a record set and then develpo the table for
displaying links to the products that are selected. The ASP
will do essentially do the following.
You want to name this Search.asp. |
<%@ Language=VBScript %> <HTML> <!-- Search.asp - Provides searching capabilities for finding products. --> <!-- #include file="include/header.asp" --> <BR> <!-- Build the search form. Note we post to this page. --> <form method="post" action="search.asp"> <!-- Table to display the search options --> <table border="0"> <!-- Display the text search option --> <tr> <td align="right"><b>Enter your search text:</b></td> <!-- Input text box --> <td align="right"><input type="text" value="<%=request("search")%>" name="Search"> </td> </tr> <!-- Provide a product price range search --> <tr><td><b>Price Range:</b></td> <td align="right">Low: <input type="text" value="<%=request("low")%>" name="Low"></td> </tr> <!-- High price search option --> <tr><td></td> <td align="right">High: <input type="text" value="<%=request("high")%>" name="High"></td> </tr> <!-- Break column --> <tr><td colspan="2"> </td></tr> <!-- Submit button --> <tr><td colspan="2" align="center"> <input type="submit" value="Submit" name="Submit"> </td></tr> </table> </form> <% ' Check to see if a search request was posted to page. if request("search") <> "" or request("low") <> "" or request("high") <> "" then
' End the check |
Notice that the Header.asp and Footer.asp are stilled being used for navigation and closure. |