Join us on Facebook!

Search db by Field

by admin 1588 views 0 Comments and 0 Rections

Providing search capabilities to a db enables users to query on whichever element you target them to. However allowing users to target which portion of the db they would like to query gives extra value. In this example, utilizing our db of US States (state, statename, and capital) the user can search in any of three fields (by dropdown menu input) rather than the application targeting one specific table element. Note: The db only has 50 observations in it, so it is better to search on single or double letter combinations. db by Field)

u_input = trim(request.form("u_input")) 'u_input is the varible for user input
' the trim function removes any blanks around the the use input
u_field=request.form("u_field") 'the dropdown varible for user inputted search field

if u_input <> "" then ' If the user entered a value query the db
accessdb="state_info" ' name of the access db
table_name="states" ' name of the table within the access db
cn="driver={microsoft access driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
sql = "select * from "& table_name &" where " & u_field & " like '%%" & u_input & "%%' "
response.write sql
rs.Open sql, cn

if rs.eof or rs.bof then
response.write "No results found..."
end if 'end check for observations
end if 'end check for user input
<% 'If there are observations then display them
if observations > 0 then %>

<% 'Write the field names
for each table_element in rs.fields %>
next %>

<% 'Write the values
do while not rs.eof
for each cell in rs.fields %>
next %>

<% rs.movenext
loop %>
<%= cell.value %>

<% end if 'end of check of obs for display %>

" method="post">

More Posts in "Tutorials"


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


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