Jump to content

drop down list


scale

Recommended Posts

Hi all,im trying to display a drop down list, which contain all the month inside, jan, feb, wed... bla bla bla...and then, when i choose jan, it wil display all infor of jan from database Access.could anyone help me? Thanks ya.

Link to comment
Share on other sites

Do you know how to set up a dropdown list? Set up your form, have the list submit whatever value you want for each month (numbers or names), and look up the information in the database. I guess I'm not sure what your specific question is, what part of this are you stuck on?

Link to comment
Share on other sites

k... my codes here...<%selected=Request.Form("a")Set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open"C:/Inetpub/wwwroot/ASP/db.mdb"Set rsSearch=Server.CreateObject("ADODB.Recordset")rsSearch.Open "select title from News WHERE month ='a';", connif rsSearch.EOF ThenResponse.Write("No Match")Elsedo until rsSearch.EOFResponse.Write (rsSearch("title"))Response.Write("<br>")rsSearch.MoveNextLoop%>when i select 1 of the month, for example jan, it wil display the record jan 1 2006 my 2nd diaryjuz display jan record only, n a link for my 2nd diary to another page...now, my problem is... 1)cannot search it, always display no match. 2) how to set the link???Thanks.

Link to comment
Share on other sites

ok i'm just presuming that you know how to create a drop down menu (dreamweaver helps alot if u have it)and you know what is a querystring (if you dont know either i can only help u with the querystring)[For the script which is supposed to retrieve and display the records]your connection code will be like this

set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("/database.mdb"))set rs=Server.CreateObject("ADODB.recordset")sql="SELECT * FROM " & tblnamers.Open sql,conn

where 'database' is the path of your database (use relative path if possible)add this at the top of your code (after the <% tag)

if request.querystring("tblname")<>"" then   tblname=request.querystring("tblname")else   tblname="sometablename"end if

where sometablename is a name of one of the tables in your databasewhen creating links for your drop down menu just add a value behind the link for example<a href="scriptname.asp?tblname=anothertablename">anothertable</a>where scriptname is the name of the script which is supposed to display the database records and anothertablename is a name of the table you want to retrieve records fromHope this helps

Link to comment
Share on other sites

  • 2 weeks later...

now im trying to create two combo boxes... ask user to select 1st combo box(month), n 2nd combo box(year), n den search record from database. now my pro is, how to combine 2 combo boxes??? it cant work if i combine it, but can work for only 1 combo box.my codes here...if monthly<>"" thenrs.Open"Select month from tbl where month='%"&monthly"%'how to add in another combo box which is year(2nd combo box)?Thanks.

Link to comment
Share on other sites

hi all,wat to say... is something like this...if combo1<>" AND combo2="" thensql=display combo1else if combo2<>"" AND combo1="" thensql=display combo2else sql=display combo1 and combo2how to write da full coding??? i tried many times, it cant work.

Link to comment
Share on other sites

if combo1<>"" and combo2="" then  rs.Open "Select month from tbl where field1='"&combo1&"'"else   if combo2<>"" and combo1="" then	rs.Open "Select month from tbl where field2='"&combo2&"'"  else	rs.Open "Select month from tbl where field1='"&combo1&"' and field2='"&combo2&"'"  end ifend if

Link to comment
Share on other sites

i try to run it, but error occur...Error Type:ADODB.Recordset (0x800A0E79)Operation is not allowed when the object is open.error line: set rs=Server.CreateObject("ADODB.Recordset")rs.Open sql, connWhat's the problem??? could any1 guide me?

Link to comment
Share on other sites

izzit like this?set rs=Server.CreateObject("ADODB.Recordset")if months <> "" and years="" thenrs.Open " SELECT title, month FROM News where month LIKE '%" &months& "%'", rs.closeelse if years <> "" and months="" thenrs.Open " SELECT title, month FROM News where year LIKE '%" &years& "%'", rs.closeelsers.Open " SELECT title, month FROM News where month LIKE '%"&months&"%' and year LIKE '%" &years& "%'", rs.closeend ifend if

Link to comment
Share on other sites

No, if you put the rs.close right after the rs.open, then you won't be able to use the data you just got. Which line is giving you the error that you showed? That error normally shows up when you try to open a recordset that is already open.

Link to comment
Share on other sites

Hi, you can try the method below:original,rsSearch.Open "select title from News WHERE month ='a';", connif a is a number, replace it intorsSearch.Open "select title from News WHERE month ='" & selected & "';", connif a isn't a number, replace it intorsSearch.Open "select title from News WHERE month =" & selected & ";", connabout problem 2, I don't what's the link and the target.Maybe you can try:add the link into this sentence:Response.Write (rsSearch("title"))-->response.write "<a href='...(link target)?xxx=" & rsSearch("title") & "...'>" & rsSearch("title") & "</a>"

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...