ASP搜索,文本域、选择列表、按钮各一,实现按标题或者按搜索
代码如下:<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%><!--#includefile="../Connections/conn.asp"...
代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Connections/conn.asp" -->
<%
Dim Recordset1__MM_type
Recordset1__MM_type = "n_title"
If (request.form("select") <> "") Then
Recordset1__MM_type = request.form("select")
End If
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.Form("search") <> "") Then
Recordset1__MMColParam = Request.Form("search")
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_conn_STRING
Recordset1_cmd.CommandText = "SELECT * FROM news WHERE ? LIKE ?"
Recordset1_cmd.Prepared = true
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 200, 1, 255, Recordset1__MM_type) ' adVarChar
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param2", 200, 1, 255, "%" + Recordset1__MMColParam + "%") ' adVarChar
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
Dim Recordset1_total
Dim Recordset1_first
Dim Recordset1_last
' set the record count
Recordset1_total = Recordset1.RecordCount
' set the number of rows displayed on this page
If (Recordset1_numRows < 0) Then
Recordset1_numRows = Recordset1_total
Elseif (Recordset1_numRows = 0) Then
Recordset1_numRows = 1
End If
' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1
' if we have the correct record count, check the other stats
If (Recordset1_total <> -1) Then
If (Recordset1_first > Recordset1_total) Then
Recordset1_first = Recordset1_total
End If
If (Recordset1_last > Recordset1_total) Then
Recordset1_last = Recordset1_total
End If
If (Recordset1_numRows > Recordset1_total) Then
Recordset1_numRows = Recordset1_total
End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (Recordset1_total = -1) Then
' count the total records by iterating through the recordset
Recordset1_total=0
While (Not Recordset1.EOF)
Recordset1_total = Recordset1_total + 1
Recordset1.MoveNext
Wend
' reset the cursor to the beginning
If (Recordset1.CursorType > 0) Then
Recordset1.MoveFirst
Else
Recordset1.Requery
End If
' set the number of rows displayed on this page
If (Recordset1_numRows < 0 Or Recordset1_numRows > Recordset1_total) Then
Recordset1_numRows = Recordset1_total
End If
' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1
If (Recordset1_first > Recordset1_total) Then
Recordset1_first = Recordset1_total
End If
If (Recordset1_last > Recordset1_total) Then
Recordset1_last = Recordset1_total
End If
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="1.asp">
<input type="text" name="search" id="search" />
<select name="select" id="select">
<option value="n_title" selected="selected">标题</option>
<option value="n_content">内容</option>
</select>
<input type="submit" name="button" id="button" value="提交" />
</form>
<%=(Recordset1_total)%>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
很简单个东西我就闹不明白为什么不行?,我试过添加请求变量,变量也能传递过来,怎么选择都传了,但为什么数据库哪里读不到记录呢,谁能给我讲讲,服务端代码是dreamweaver里查询记录集生成的。 展开
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Connections/conn.asp" -->
<%
Dim Recordset1__MM_type
Recordset1__MM_type = "n_title"
If (request.form("select") <> "") Then
Recordset1__MM_type = request.form("select")
End If
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.Form("search") <> "") Then
Recordset1__MMColParam = Request.Form("search")
End If
%>
<%
Dim Recordset1
Dim Recordset1_cmd
Dim Recordset1_numRows
Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
Recordset1_cmd.ActiveConnection = MM_conn_STRING
Recordset1_cmd.CommandText = "SELECT * FROM news WHERE ? LIKE ?"
Recordset1_cmd.Prepared = true
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 200, 1, 255, Recordset1__MM_type) ' adVarChar
Recordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param2", 200, 1, 255, "%" + Recordset1__MMColParam + "%") ' adVarChar
Set Recordset1 = Recordset1_cmd.Execute
Recordset1_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
Dim Recordset1_total
Dim Recordset1_first
Dim Recordset1_last
' set the record count
Recordset1_total = Recordset1.RecordCount
' set the number of rows displayed on this page
If (Recordset1_numRows < 0) Then
Recordset1_numRows = Recordset1_total
Elseif (Recordset1_numRows = 0) Then
Recordset1_numRows = 1
End If
' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1
' if we have the correct record count, check the other stats
If (Recordset1_total <> -1) Then
If (Recordset1_first > Recordset1_total) Then
Recordset1_first = Recordset1_total
End If
If (Recordset1_last > Recordset1_total) Then
Recordset1_last = Recordset1_total
End If
If (Recordset1_numRows > Recordset1_total) Then
Recordset1_numRows = Recordset1_total
End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (Recordset1_total = -1) Then
' count the total records by iterating through the recordset
Recordset1_total=0
While (Not Recordset1.EOF)
Recordset1_total = Recordset1_total + 1
Recordset1.MoveNext
Wend
' reset the cursor to the beginning
If (Recordset1.CursorType > 0) Then
Recordset1.MoveFirst
Else
Recordset1.Requery
End If
' set the number of rows displayed on this page
If (Recordset1_numRows < 0 Or Recordset1_numRows > Recordset1_total) Then
Recordset1_numRows = Recordset1_total
End If
' set the first and last displayed record
Recordset1_first = 1
Recordset1_last = Recordset1_first + Recordset1_numRows - 1
If (Recordset1_first > Recordset1_total) Then
Recordset1_first = Recordset1_total
End If
If (Recordset1_last > Recordset1_total) Then
Recordset1_last = Recordset1_total
End If
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="1.asp">
<input type="text" name="search" id="search" />
<select name="select" id="select">
<option value="n_title" selected="selected">标题</option>
<option value="n_content">内容</option>
</select>
<input type="submit" name="button" id="button" value="提交" />
</form>
<%=(Recordset1_total)%>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
很简单个东西我就闹不明白为什么不行?,我试过添加请求变量,变量也能传递过来,怎么选择都传了,但为什么数据库哪里读不到记录呢,谁能给我讲讲,服务端代码是dreamweaver里查询记录集生成的。 展开
2个回答
展开全部
唉,可怜的人啊,十多行的代码,被DW生成了一百多行沉余代码,DW害人不浅啊。
DW的代码应该没人帮你看哦,至少我不会看。
如果你只是想解决问题,你可以等别人来回答吧,当我白说。
如果你真想学ASP,那么,不要问为什么,立即卸载DW,完全手工写代码(十余年经验之谈)。
DW的代码应该没人帮你看哦,至少我不会看。
如果你只是想解决问题,你可以等别人来回答吧,当我白说。
如果你真想学ASP,那么,不要问为什么,立即卸载DW,完全手工写代码(十余年经验之谈)。
追问
可能是我不懂,如果您有10年经验,您应该看得懂,前面服务器脚本很多废行是为以后加操作记录集用的,完全可以忽略不看,HTML代码在补充里面,愿意帮忙解决问题谢谢您,至于浪费您的宝贵时间还没回答我的疑惑,我不想评论任何!
这些您能说是废行吗?谢谢,我想解决问题
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询