PDA

View Full Version : Using select option to output results


lebronletchev
11-11-2008, 11:09 AM
Dear friends,

Coult I output the results from a table using select option? I was tried but no success. That is my script:

<html>
<head>
<title>Untitled</title>
</head>

<body>



<%
' ADO Constants - Don't Change Them
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdText = &H0001
Const adUseClient = 3

Dim cSql

DIM strKeyword
strKeyword = Request.QueryString("SOURCE")

DIM nbrKeyword
nbrKeyword = Request.QueryString("source_no")



set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/dbfiles/test.mdb"))
set rs2 = Server.CreateObject("ADODB.recordset")

rs2.open "SELECT * FROM TABLE1 " ,conn, adOpenForwardOnly, adLockReadOnly, adCmdText
%>


<%while not rs2.EOF%>
<%IF NOT RS2.EOF THEN%>

<form method="get" action="nextfile.asp">


<input type="radio" name="fileidx" value=<%=rs2("source_no") %>><%=rs2("TITLE")%><br>
<TR align=middle vAlign=center>
<TD align=right height=40 noWrap>&nbsp;</TD>

<TD>&nbsp;&nbsp;<SELECT name="look_for">
<OPTION selected
value=<%=rs2("source_no") %>> <%=rs2("TITLE")%></OPTION>

</SELECT>&nbsp;&nbsp;</FONT>
<CENTER></CENTER></TD>
<TD><input type="button" value="Go!" style="height : 25; width : 30;" onClick="makeWord(this.form.look_for)">
&nbsp;</TD></TD></TR>


<%rs2.MoveNext%>
<%END IF%>
<%wend%>

<input type="submit">
</form>

<%
rs2.close

conn.close%>





</body>
</html>


Thank you for your assistance.

Lebron

hinch
11-11-2008, 12:13 PM
<html>
<head>
<title>Untitled</title>
</head>

<body>

<%

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("./dbfiles/test.mdb")
set rs2 = Server.CreateObject("ADODB.recordset")

rs2.open "SELECT * FROM TABLE1 " ,conn
%>

<form method="get" action="nextfile.asp">
<table>
<%
if not rs2.EOF then
do while not rs2.EOF
%>
<TR align=middle align=center>
<TD>&nbsp;&nbsp;
<SELECT name="look_for">
<OPTION selected value='<%=rs2("source_no") %>'> <%=rs2("title")%></OPTION>
</SELECT>
</TD>
<TD><input type="button" value="Go!" style="height : 25; width : 30;" onClick="makeWord(this.form.look_for)">
&nbsp;</TD>
</TR>

<%
rs2.MoveNext
loop
end if
%>
<tr><td colspan="2">
<input type="submit">
</td></tr>
</table>
</form>

<%
rs2.close

conn.close%>

</body>
</html>

lebronletchev
11-11-2008, 12:35 PM
Thanks.

Sorry, but it repeat <select option> for each record in my table, When I want to see JUST one <select option> with all records output from the table.

thanks again

Lebron

hinch
11-11-2008, 02:14 PM
you just need to move some bits outside of the loop thats all

%

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("./dbfiles/test.mdb")
set rs2 = Server.CreateObject("ADODB.recordset")

rs2.open "SELECT * FROM TABLE1 " ,conn
%>

<form method="get" action="nextfile.asp">
<table>
<TR align=middle align=center>
<TD>&nbsp;&nbsp;
<SELECT name="look_for">
<%
if not rs2.EOF then
do while not rs2.EOF
%>
<OPTION selected value='<%=rs2("source_no") %>'> <%=rs2("title")%></OPTION>
<%
rs2.MoveNext
loop
end if
%>
</SELECT>
</TD>
<TD><input type="button" value="Go!" style="height : 25; width : 30;" onClick="makeWord(this.form.look_for)">
&nbsp;</TD>
</TR>
<tr><td colspan="2">
<input type="submit">
</td></tr>
</table>
</form>

<%
rs2.close

conn.close%>

lebronletchev
11-11-2008, 03:14 PM
Thank you so much! Indeed, you code will be very, very useful.

Best for all.

Lebron