dcsimg

Searching the List

By ServerWatch Staff (Send Email)
Posted Apr 16, 2000


Part 2 - Allowing users to query the database filling a HTML form in. Stefano Lanfranconi

Part 2 - Allowing users to query the database filling a HTML form in.
 
In this article I'd like to show you how to allow your users to send requests to the server, in a more interesting way than simply click on an alphabet letter.
 
This aim will be reached by using a standard HTML form (Form.asp) that users will have to fill in as shown in Figure 1. When the sumbit button will be clicked, code inside SearchColumnists.asp will query the database and show the consequent results.
 
Before to control how server-side VBScript can help us in building our two pages, let's normalize the columnists' database (Swynk2.mdb) splitting off Columnists into two separated yet correlated tables.
Informations formerly contained in Topic field, will be better managed creating a dedicated table called Topics and setting a relationship between its counter field idTopic and that with the same name added to Columnists table instead of Topic.

VBScript code within the two ASP pages

Form.asp
After having settled up our connection, we get the ts recordset to populate the SELECT tag showing users the list of topics treated at Swink site.
<%
      vConnName = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("Swynk2.mdb")
      Set Conn = Server.CreateObject("ADODB.Connection")
      Conn.Open vConnName
               
      vSql = "SELECT * From Topics Order by Topic;"
      set ts = Conn.Execute(vSql)
%>

<SELECT name=selTopic>
                     <OPTION SELECTED value=0>any topics</OPTION>
                    
<%Do until ts.eof%>
                          <OPTION value='<%=ts("idTopic")%>'>
                          <%=ts("Topic")%></OPTION>
                     <%ts.MoveNext Loop%>
</SELECT>
          
The only other code we have to write within Form.asp is that used to build our well known alphabetic rows.

<table WIDTH="85%" ALIGN="center" BORDER="0" CELLSPACING="1" CELLPADDING="1">
     
         <%  = CreateAlphabetInTableRows("Silver", 1) %>
    
</table>

As shown in the following HTML row, when the sumbit button is clicked, SearchColumnists.asp will be requested to the server.

<FORM action="SearchColumnists.asp?form=1" method=POST>


The HTML form you can use to tune your requests.
Figure 1
 


Two correlated MSAccess tables from one.
Figure 2
 

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.