beccatigger Posted January 24, 2005 Posted January 24, 2005 (edited) Hi, Long time no see!I've got a major problem that's annoying me loads!I've got this big project website that I've got to create using ASP and running a MS access db behind. It's a book database with a book table with book name, book ID, subject_area, etc.etc. I want to make a pull down menu with the subject areas in so you can display the results from a chosen category.So far, for the form, I've got this:this is the search page search.asp<html> <head><title>List Box Titles</title><head><body><h2>Search by subject category</h2><p><br><form method="get" action="results.asp"> <select name="subject" size="1"><option value=accountancy>Accountancy</option><option value=computing>Computing</option><option value=dvds>DVDs</option></select><input type="submit"></form></body></html>then the results.asp is this:<html> <head><title>Title Response</title><head><body><h1>Bibliographic Data</h1><%varTitle= request.querystring("subject")Set oRp=server.createobject("ADODB.recordset")sqltext="Select * from books WHERE subject_area = "';response.write "<p> Title Searched: <b>" & subject_area &"</b>"orp.open sqltext, "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("shop.mdb")if orp.eof then response.write varTitle & " Not Found"elseresponse.write "<p>The Bibliographic Data is as follows:<br>"response.write "<p>Book: <b>" & orp("Book_Name") & "</b><br>"end ifresponse.write "<p> <a href='search.asp'>Another search</a>"%></body></html>The bit hightlighted in red is wrong but i don't know how to reference it (maybe to the query string but I don't know how to?!)I'd be grateful for any help! Edited January 25, 2005 by prathapml
Carmon Posted January 25, 2005 Posted January 25, 2005 i think this shud be in the Web development section
IcemanND Posted January 25, 2005 Posted January 25, 2005 Welcome back, try thisedited: to replace servervariables with querystring. This should create your sql statement:sqltext="Select * from books WHERE subject_area = '" & request.querystring("subject") & "'"This should display on the page what request was:response.write (" Title Searched: <b>" & request.querystring("subject") & "</b>")
hazard0usIntent Posted January 25, 2005 Posted January 25, 2005 Actually this line is getting the value of the submitted form field:varTitle= request.querystring("subject")So the SQl statement just needs to be:sqltext="Select * from books WHERE subject_area = '" & varTitle & "'"Use request.querystring("form field name") to reference fields submitted in a form with a method of "get".Use request.form("form field name") to reference fields submitted in a form with a method of "post".I would not recommend using request.servervariables to reference submitted form fields as the methods above are more direct and efficient.
IcemanND Posted January 25, 2005 Posted January 25, 2005 oops, that is what I meant to use. QUERYSTRING not SERVERVARIABLES.I edited my previous post to fix it
beccatigger Posted January 26, 2005 Author Posted January 26, 2005 OK, It took me a day, but I figured it outYou have to make a form, but it doesnt need a recordset as I suspected)However, the results page needs to link from that pull down menu. So u name the <select> tag so I named it category. Then when I made the recordset for the second page, you then filter the subject_area from books table with the url category, so when it flips onto the results page,then url would be, e.g.:search.asp?category=ITHere's the code examples, in case anybody ever has to go through the hell of making one of these babys:<%@LANGUAGE="VBSCRIPT"%><!--#include file="Connections/query.asp" --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link href="styling.css" rel="stylesheet" type="text/css"></head><body><form action="search.asp" method="get" name="category"> <select name="category" size="1" style="font-size:12px;color:#006699;font-family:verdana;background-color:#ffffff;" > <option value="MS Office"><font class="pulldown">MS Office</font></option> <option value="ICT">ICT</option> <option value="Programming">Programming</option> <option value="Networking">Networking</option> <option value="Internet">Internet</option> <option value="Games">Games</option> <option value="DVDs">DVDs</option> <option value="Videos">Videos</option> <option value="Other">Other</option> </select> <input type=submit value="Submit!"></form></body></html>and the results page looks like this:<%@LANGUAGE="VBSCRIPT"%> <!--#include file="Connections/searching.asp" --><%Dim Recordset1__MMColParamRecordset1__MMColParam = "1"If (Request.QueryString("category") <> "") Then Recordset1__MMColParam = Request.QueryString("category")End If%><%Dim Recordset1Dim Recordset1_numRowsSet Recordset1 = Server.CreateObject("ADODB.Recordset")Recordset1.ActiveConnection = MM_searching_STRINGRecordset1.Source = "SELECT * FROM Books WHERE Subject_area = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"Recordset1.CursorType = 0Recordset1.CursorLocation = 2Recordset1.LockType = 1Recordset1.Open()Recordset1_numRows = 0%><%Dim Repeat1__numRowsDim Repeat1__indexRepeat1__numRows = -1Repeat1__index = 0Recordset1_numRows = Recordset1_numRows + Repeat1__numRows%><% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %><table border=2> <tr> <td><a href="details.asp?ID=<%=(Recordset1.Fields.Item("ID").Value)%>"><%=(Recordset1.Fields.Item("ID").Value)%></a></td> </tr> <tr> <td><%=(Recordset1.Fields.Item("Book_Name").Value)%><br></td> </tr> <tr> <td><%=(Recordset1.Fields.Item("Edition_number").Value)%></td> </tr></table><% Repeat1__index=Repeat1__index+1 Repeat1__numRows=Repeat1__numRows-1 Recordset1.MoveNext()Wend%><%Recordset1.Close()Set Recordset1 = Nothing%>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now