2 Column Split Search Results from Access #2:
Code:
Download Sample Database
search.asp
Highlight
<%option explicit%> <% dim conn, rs, rs2, strconn, strsql, strsql2 set conn = server.createobject("adodb.connection") set rs = server.createobject("adodb.recordset") set rs2 = server.createobject("adodb.recordset") conn.open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & server.mappath("test.mdb") strsql = "select Name from test" strsql2 = "select distinct Division from test" rs.open strsql, conn, 2, 2 rs2.open strsql2, conn, 2, 2 %>
<%if request.querystring("Results") = "False" then%>
Sorry, there are no matching records.
<%end if%>
Name:
--Select a Name--
<%if not rs.eof then do while not rs.eof%>
"><%=rs("Name")%>
<%rs.movenext loop end if%>
Division:
--Select a Division--
<%if not rs2.eof then do while not rs2.eof%>
"><%=rs2("Division")%>
<%rs2.movenext loop end if%>
<% rs.close rs2.close conn.close set rs = nothing set rs2 = nothing set conn = nothing %>
list.asp
Highlight
<%option explicit%> <% dim conn, rs, strconn, strsql, Count set conn = server.createobject("adodb.connection") set rs = server.createobject("adodb.recordset") conn.cursorlocation = 3 conn.open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & server.mappath("test.mdb") strsql = "select * from test where" If request.querystring("Name") <> "" Then strsql = strsql & " Name = '" &_ request.querystring("Name") & "' and " End If If request.querystring("Division") <> "" Then strsql = strsql & " Division = '" & _ request.querystring("Division") & "' and " End If strsql = left(strsql,(len(strsql) - 5)) rs.open strsql,conn, adopenforwardonly, adlockreadonly %> <% if rs.eof then rs.close conn.close set rs = nothing set conn = nothing response.redirect "search.asp?Results=False" else response.write "
" do until rs.eof %>
<%=rs("Name")%> - <%=rs("Division")%>
<% rs.movenext if rs.recordcount = 1 then ' -- do nothing elseif rs.eof then response.write "
" else%>
<%=rs("Name")%> - <%=rs("Division")%>
<%rs.movenext end if %>
<%loop%>
<% end if rs.close conn.close set rs = nothing set conn = nothing %>