Join us on Facebook!
28
Feb

Multiple Form Selection (Where In)

by admin 1151 views 0 Comments and 0 Rections

Allowing multiple choices of data observations enables people to customize views of your data and adds value to your applications. The following example utilizes our db on the career statistics of Hammerin’ Hank Greenberg. The years he played are available to select from in a dropdown menu. When multiple years are selected they are passed comma delimited. Utilizing the where in statement in our sql the comma delimited selections are appended to our sql statement to display only those years selected. Because we are looking for numeric values in our where in statement no modification to the comma delimited input is necessary. When character input is involved a replace statement can be used to put the appropriate quotation marks into your statement. Which is also provided in this example, but must be un-commented to be used.

  
CodeAve.com(Multiple Form Selection (Where In) )

<%' Check to see if there is any input
' if not display the form for input
u_input=request.form("u_input")
if u_input = "" then %>

" method="post">
Select one, many, or all years to display





<%' When there is input display the data
else
' Name of the Access db
accessdb="greenberg"

' Connection to the db
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server record set object
set rs = server.createobject("ADODB.Recordset")

' Create an sql statement that will select all the table elements
' A single selection will simply query for that year
' Multiple selections will be passed
' already comma delimited. Which is fine for numerics
' However for text queries uncomment the two lines below
' beginging with u_input and uncomment the sql query for alpha

' For text queries u_input will need to be comma delimited and in single quotes
' We replace the commas with ',' and change the sql to include single quotes around u_input
' u_input="Detroit,Pittsburgh"
' u_input=replace(u_input,",","','")

' The sql statement is written to the browser
' to demonstrate this.
sql = "select * from hammerin_hank where year in("& u_input &")" 'sql for numerics

'sql = "select * from hammerin_hank where team in('"& u_input &"')" 'sql for alpha
' Execute the sql
rs.Open sql, cn
%>



<% ' Write out all the elements requested in the
' sql statement as table headers
for each element in rs.fields%>

<% next
' End table headers %>


<% ' Write out all the values in the record
do while not rs.eof
for each element in rs.fields %>

<%
next
' end of record %>

<% ' Move to the next record
rs.movenext
' Loop to the beginning
loop%>
<%= sql%>
<%= element.name %>
<%= rs(element.name) %>


* In Military Service

<% end if 'End check for user input %>

More Posts in "Tutorials"

Comments

blog comments powered by Disqus

Feed Subscription

Get daily inboxed with latest news, reviews and tutorials. Signup now it's free :)



Planetmaks on Twitter

Follow PlanetMaks on Facebook

Recent Comments

Powered by Disqus

Tags

32Bit 64Bit 7 Admin Tool Admin Tools Admin-Tool Admin-Tools AdminTool Adobe Adware All-in-One Anti-Spyware Anti-Virus Apple Backup Tools Browser Browsers Changing Default Directory Codec Data Recovery Download Manager Downloads Drive Utilities Driver Drivers Firefox Flash Freeware Google Graphics Internet Tool Internet-Tool Messaging Microsoft Microsoft Tool Micsellonous Monitoring Multimedia Networking News NVidia Office Tool Office-Tool PC Suite Press Release Registry Samsung Security Shareware Software Softwares Tutorials Vista Windows Windows 7 Windows 8