asp+access如何做站内搜索?
2个回答
展开全部
个人写的一小部分代码供楼主参考,最主要是要构建SQL语句,代码如下:
<form action="list.asp" method="post">
请输入你要查询的条件:
标题:<input type="text" name="Title" size=10>
作者:<input type="text" name="Author" size=20>
<input type="submit" value="查询">
</form>
<table border="1" width="100%" id="table1">
<tr bgcolor="red">
<td>标题</td>
<td>作者</td>
</tr>
<%
Dim Title,Author
Title = Trim(Request("Title")) '接收用户输入的姓名信息
Author = Trim(Request("Author")) '接收用户输入的电话信息
Dim NowPage
NowPage = Request("page") '接收你超链接的页码值并赋值给变量NowPage
if NowPage = "" then '如果你没有输入查看的页码,那么显示第一页
NowPage = 1
end If
If IsNumeric(NowPage) Then '页码是数字则转换成整型数据,不是数字则显示第一页
NowPage = CInt(NowPage)
Else
NowPage = 1
End If
If NowPage < 1 Then '如果页码值小于1,则为第一页
NowPage = 1
End If
%>
<!--#include file="Conn.asp"-->
<%
set rs=server.createobject("adodb.recordset")
sql="SELECT * FROM 新闻 Where 是否发布 = True " '由于是输入查询所以需构建SQL语句,模糊查询必须是%
If Title <> "" Then
sql = sql & " and (标题 like '%"&Title&"%') "
End If
If Author <> "" Then
sql = sql & " and (作者 like '%"&Author&"%') "
End If
sql = sql & " ORDER BY 编号 DESC"
rs.open sql,conn,1,1
If Not rs.eof And Not rs.bof Then '如果查询到数据则执行
rs.PageSize = 4 '设置每页显示4条数据记录
ReCount = rs.RecordCount '把查询到的总记录数据赋值给变量ReCount
PgCount = rs.PageCount '把总页码数赋值给变量PgCount
If NowPage > PgCount Then '页码数值如果大于总页码数则只能为最后一页
NowPage = PgCount
End If
rs.AbsolutePage = NowPage '设置当前用户正在浏览第几页
do while (not rs.EOF) And (i<rs.pageSize) '注意必须判断i<rs.pageSize
Response.Write "<tr>"
Response.Write "<td><a href=ShowNews.asp?ID="&rs("编号")&">"&rs("标题")&"</a></td>"
Response.Write "<td>" & rs("作者") & "</td>"
Response.Write "</tr>"
i = i + 1
rs.MoveNext
Loop
Else
response.write "<tr><td colspan=""4"">找不到你查询的数据</td></tr>"
End If
rs.close
set rs=nothing
conn.Close
set conn=Nothing
response.write "<tr><td colspan=""2"" align=""center"">"
Response.Write "<a href=list.asp?page=1&xm="&xm&"&Author="&Author&">首页</a> "
Response.Write "<a href=list.asp?page="&NowPage-1&"&Title="&Title&"&dh="&dh&">前一页</a> "
Response.Write "<a href=list.asp?page="&NowPage+1&"&Title="&Title&"&dh="&dh&">后一页</a> "
Response.Write "<a href=list.asp?page="&PgCount&"&Title="&Title&"&dh="&dh&">末页</a>"
Response.Write "<hr>"
Response.Write "现在是第"&NowPage&"/"&PgCount&"页,共有"&ReCount&"条数据记录"
response.write "</td></tr>"
%>
</table>
觉得对你有帮助的话,请楼主结贴加分
<form action="list.asp" method="post">
请输入你要查询的条件:
标题:<input type="text" name="Title" size=10>
作者:<input type="text" name="Author" size=20>
<input type="submit" value="查询">
</form>
<table border="1" width="100%" id="table1">
<tr bgcolor="red">
<td>标题</td>
<td>作者</td>
</tr>
<%
Dim Title,Author
Title = Trim(Request("Title")) '接收用户输入的姓名信息
Author = Trim(Request("Author")) '接收用户输入的电话信息
Dim NowPage
NowPage = Request("page") '接收你超链接的页码值并赋值给变量NowPage
if NowPage = "" then '如果你没有输入查看的页码,那么显示第一页
NowPage = 1
end If
If IsNumeric(NowPage) Then '页码是数字则转换成整型数据,不是数字则显示第一页
NowPage = CInt(NowPage)
Else
NowPage = 1
End If
If NowPage < 1 Then '如果页码值小于1,则为第一页
NowPage = 1
End If
%>
<!--#include file="Conn.asp"-->
<%
set rs=server.createobject("adodb.recordset")
sql="SELECT * FROM 新闻 Where 是否发布 = True " '由于是输入查询所以需构建SQL语句,模糊查询必须是%
If Title <> "" Then
sql = sql & " and (标题 like '%"&Title&"%') "
End If
If Author <> "" Then
sql = sql & " and (作者 like '%"&Author&"%') "
End If
sql = sql & " ORDER BY 编号 DESC"
rs.open sql,conn,1,1
If Not rs.eof And Not rs.bof Then '如果查询到数据则执行
rs.PageSize = 4 '设置每页显示4条数据记录
ReCount = rs.RecordCount '把查询到的总记录数据赋值给变量ReCount
PgCount = rs.PageCount '把总页码数赋值给变量PgCount
If NowPage > PgCount Then '页码数值如果大于总页码数则只能为最后一页
NowPage = PgCount
End If
rs.AbsolutePage = NowPage '设置当前用户正在浏览第几页
do while (not rs.EOF) And (i<rs.pageSize) '注意必须判断i<rs.pageSize
Response.Write "<tr>"
Response.Write "<td><a href=ShowNews.asp?ID="&rs("编号")&">"&rs("标题")&"</a></td>"
Response.Write "<td>" & rs("作者") & "</td>"
Response.Write "</tr>"
i = i + 1
rs.MoveNext
Loop
Else
response.write "<tr><td colspan=""4"">找不到你查询的数据</td></tr>"
End If
rs.close
set rs=nothing
conn.Close
set conn=Nothing
response.write "<tr><td colspan=""2"" align=""center"">"
Response.Write "<a href=list.asp?page=1&xm="&xm&"&Author="&Author&">首页</a> "
Response.Write "<a href=list.asp?page="&NowPage-1&"&Title="&Title&"&dh="&dh&">前一页</a> "
Response.Write "<a href=list.asp?page="&NowPage+1&"&Title="&Title&"&dh="&dh&">后一页</a> "
Response.Write "<a href=list.asp?page="&PgCount&"&Title="&Title&"&dh="&dh&">末页</a>"
Response.Write "<hr>"
Response.Write "现在是第"&NowPage&"/"&PgCount&"页,共有"&ReCount&"条数据记录"
response.write "</td></tr>"
%>
</table>
觉得对你有帮助的话,请楼主结贴加分
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询