`
luliangok
  • 浏览: 831795 次
文章分类
社区版块
存档分类
最新评论

asp中建立搜索的不同方法

 
阅读更多

searchfunction:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
sub searchinfo()

'如果是新查询''''''''''''''''''''
if request("search")="1" then
session("sessionok")=""
end if

''''''''''''''''''''''''''''''''如果不是新查询
dim select1,select2,selectyear,selectmonth,key
if session("sessionok")="ok" then
select1=session("select1")'按栏目
select2=session("select2")'按产品厂商或产品类别
selectyear=session("selectyear")
selectmonth=session("selectmonth")
selectdate=session("selectdate")'按日期
key=session("key")'关键字
else
select1=request("select1")'按栏目
select2=request("select2")'按其它
selectyear=request("selectyear")'按年
selectmonth=request("selectmonth")'按月
selectdate=selectyear &"-"& selectmonth &"-"&"01 01:01:01"
key=trim(request("key"))
if key="" then
response.Write("关键字不能为空!")
response.End()
end if
if select1="" and select2="" and selectyear="" then
response.Write("对不起,你没有指定条件!")
response.End()
end if
session("select1")=request("select1")'按栏目
session("select2")=request("select2")'按其它
session("selectyear")=request("selectyear")'按年
session("selectmonth")=request("selectmonth")'按月
session("selectdate")=selectyear &"-"& selectmonth &"-"&"01 00:00:00"
session("key")=trim(request("key"))
session("sessionok")="ok"
end if
'只选择按栏目查询
if select1<>"" and selectyear="" and select2="" then
search="newstype='"&select1&"' and title like '%"&key&"%' or newstype='"&select1&"' and content like '%"&key&"%' order by id desc"

sql="select title,id,createtime,newstype,url from T_news where "&search
end if
'按栏目和时间查询
if select1<>"" and selectyear<>"" and select2="" then
search="newstype='"&select1&"' and title like '%"&key&"%' and createtime>'"&selectdate&"' or newstype='"&select1&"' and content like '%"&key&"%' and createtime>'"&selectdate&"' order by id desc"

sql="select title,id,createtime,newstype,url from T_news where "&search
end if

'按栏目和厂商、产品类型查询
if select1<>"" and selectyear="" and select2<>"" then
if select2="cs" then
search="newstype='"&select1&"' and company like '%"&key&"%' order by T_news.id desc"
else
search="newstype='"&select1&"' and type like '%"&key&"%' order by T_news.id desc"
end if

sql="select title,T_news.id,createtime,newstype,T_news.url from T_co join T_news on T_co.id=T_news.companyid join T_class on T_news.classid=T_class.id where "&search
end if

'按栏目和时间和厂商、产品类型查询
if select1<>"" and selectyear<>"" and select2<>"" then
if select2="cs" then
search="newstype='"&select1&"' and createtime>'"&selectdate&"' and company like '%"&key&"%' order by T_news.id desc"
else
search="newstype='"&select1&"' and createtime>'"&selectdate&"' and type like '%"&key&"%' order by T_news.id desc"
end if

sql="select title,T_news.id,createtime,newstype,T_news.url from T_co join T_news on T_co.id=T_news.companyid join T_class on T_news.classid=T_class.id where "&search
end if

'按厂商、产品类型查询
if select2<>"" and select1="" and selectyear="" then
if select2="cs" then
search="company like '%"&key&"%' order by T_news.id desc"
else
search="type like '%"&key&"%' order by T_news.id desc"
end if
sql="select title,T_news.id,createtime,newstype,T_news.url from T_co join T_news on T_co.id=T_news.companyid join T_class on T_news.classid=T_class.id where "&search
end if

'按厂商、产品类型和时间查询

if select2<>"" and select1="" and selectyear<>"" then
if select2="cs" then
search="company like '%"&key&"%' and createtime>'"&selectdate&"' order by T_news.id desc"
else
search="type like '%"&key&"%' and createtime>'"&selectdate&"' order by T_news.id desc"
end if

sql="select title,T_news.id,createtime,newstype,url from T_co join T_news on T_co.id=T_news.companyid join T_class on T_news.classid=T_class.id where "&search
end if


'按时间查询
if select1="" and selectyear<>"" and select2="" then
search="title like '%"&key&"%' and createtime>'"&selectdate&"' or content like '%"&key&"%' and createtime>'"&selectdate&"' order by id desc"

sql="select title,id,createtime,newstype,url from T_news where "&search
end if

dim rs2
'sql="select title,T_news.id,createtime,newstype from T_co join T_news on T_co.id=T_news.companyid join T_class on T_news.classid=T_class.id where "&search
'response.Write(session("ok"))
'response.write sql
'response.end
set rs2=server.CreateObject("adodb.recordset")
rs2.open sql,conn,1,1
%>
<body leftmargin="0" topmargin="0"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
<%
if rs2.eof and rs2.bof then
response.Write("&nbsp;&nbsp;没有找到记录!")
else
page=request("page")
if page="" then page="1"
rs2.pagesize=48
rs2.absolutepage=clng(page)
%>
<tr>
<td width="0%"></td>
<td colspan="2">关键字&nbsp;<font color="#CC0000"><u><%=key%></u></color><font color="#000000">&nbsp;的检索结果:</font></td>
<tr>
<%
for i=1 to rs2.pagesize
if rs2.eof then exit for
newstype=rs2("newstype")
select case newstype
case "yj"
linke="zw_yjxw.asp"
case "mz"
linke="zw_mzcy.asp"
case "xc"
linke="zw_xpfb.asp"
case "cy"
linke="zw_cyts.asp"
case "qy"
linke="index-6.asp"
case "js"
linke="zw_jsyy.asp"
case "sj"
linke="zw_sjsl.asp"
end select
%>
<tr>
<td></td>
<td width="80%" height="22"><font size="1">◆&nbsp;</font>&nbsp;<font color="#0033CC">
<%if isnull(rs2("url")) or rs2("url")="" then%>
<a href="<%response.write (linke)%>?id=<%=rs2("id")%>" target="_blank">
<%else%>
<a href="../<%=rs2("url")%>" target="_blank">
<%end if%>
<font color="#0033CC"><%=left(rs2("title"),22)%></font></a>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
<td><font color="#0033CC"><%=FormatDateTime(rs2("createtime"),2)%></font></td>
</tr>
<%
rs2.movenext
next
end if
%>
<tr>
<td></td>
<td colspan="2"><br> <hr align="left" width="100%">
<font size="2">
<%
if rs2.pagecount=1 then'如果只有一页则不必分页
else
p_i=request("P_i")'记录起始位置
if p_i="" then
p_i=1
else
p_i=clng(P_i)
end if

if clng(page)>1 then'如果当前不只一页
if clng(page)=p_i then
response.write("<a href='search.asp?page="&page-1&"&p_i="&(p_i)-10&"'>上一页</a>&nbsp;&nbsp;")
else
response.write("<a href='search.asp?page="&page-1&"&p_i="&p_i&"'>上一页</a>&nbsp;&nbsp;")
end if
end if
for i=p_i to rs2.pagecount
if i mod 10 = 0 then
if i=clng(page) then
response.write ("<font color='#333333'>[</font><font color=red>"&i&"</font><font color='#333333'>]</font>")
else
response.write ("<font color='#333333'>[<a href='search.asp?page="&i&"&p_i="&p_i&"'>"&i&"</a>]</font>")
end if
response.Write("&nbsp;&nbsp;")
if clng(page)=i then
P_i=p_i+10
end if
if clng(page)=i then
bottom=true
end if
exit for
end if
if i=clng(page) then
response.write ("<font color='#333333'>[</font><font color=red><b>"&i&"</b></font><font color='#333333'>]</font>")
else
response.write ("<font color='#333333'>[<a href='search.asp?page="&i&"&p_i="&p_i&"'>"&i&"</a>]</font>")
end if
response.Write("&nbsp;&nbsp;")
next
if rs2.pagecount>1 then
if clng(page)=rs2.pagecount then
else
response.write ("<a href='search.asp?page="&page+1&"&p_i="&p_i&"'>下一页</a>")

end if
end if
end if
%>
</font> </td>
</tr>
</table>
<%
end sub
%>


分享到:
评论

相关推荐

    asp站内搜索

    在ASP技术中,站内搜索是提升用户体验、增加网站互动性的重要功能,它允许用户快速找到网站内部特定的信息,如帖子的标题或内容字段。下面我们将深入探讨ASP实现站内搜索的关键技术和步骤。 一、数据库设计 在实现...

    用ASP建立站内信息搜索系统

    本文将详细介绍如何使用ASP建立一个站内信息搜索系统。 **第一步:数据库准备** 首先,我们需要创建一个数据库来存储待搜索的信息。这里使用Access 97创建一个名为`list.mdb`的数据库,并在其中建立一个名为`list`...

    搜索引擎网站ASp源码

    在ASP中,这可能是一个表单提交事件,通过POST或GET方法将关键词发送到服务器。 2. **数据抓取和索引**:搜索引擎需要抓取大量网页并建立索引。在ASP中,这可能涉及到HTTP请求库来获取网页内容,然后使用正则表达式...

    asp 站内搜索功能 代码整合

    ASP中常见的数据库接口有ADO(ActiveX Data Objects),通过Connection对象建立与数据库的连接,然后使用Recordset对象执行SQL查询语句。例如,使用`ADODB.Connection`和`ADODB.Recordset`对象,编写SQL语句如`...

    ASP站内搜索引擎代码

    在ASP中,这通常通过ADO(ActiveX Data Objects)实现,如建立Connection对象,执行SQL查询,并通过Recordset对象来处理结果。 2. **查询构造**:用户输入的关键词需要转化为有效的SQL查询语句。开发者需要对输入...

    大型ASP搜索引擎

    在压缩包文件“syzf.net.lyf.32304”中,可能包含了该大型ASP搜索引擎的源代码和其他相关资源。源码分析可以帮助我们深入了解其工作原理,学习如何实现这样的搜索引擎,以及可能存在的优化空间。对于开发者来说,这...

    asp.net搜索模块

    ASP.NET 搜索模块是用于构建网站内部搜索引擎的功能组件,尤其适用于中小规模的网站。这个模块使得用户能够在网站中快速、高效地找到所需信息,提升用户体验并增加网站的互动性。在 ASP.NET 平台上,我们可以利用...

    asp+access搜索引擎

    在"asp+access搜索引擎"中,ASP将用于接收用户的搜索请求,处理这些请求,并将结果显示到网页上。 接着,我们来看Access数据库。Access提供了简单易用的界面来创建、管理和查询数据。在搜索引擎的背景下,我们可以...

    asp源码—ASP站内模糊搜索例范源码 v1.0.zip

    在ASP源码中,"ASP站内模糊搜索例范源码 v1.0.zip" 提供了一个完整的模糊搜索功能实现,这对于任何需要在网站内部提供高效、灵活搜索功能的应用都极其重要。 模糊搜索允许用户输入部分关键词或者带有拼写错误的...

    商品搜索页面,asp。net

    在这个商品搜索页面的项目中,我们看到开发者使用了C#作为主要的编程语言,这是一种面向对象的编程语言,与ASP.NET框架结合得非常紧密。 在ASP.NET中,商品搜索功能通常涉及到以下几个关键知识点: 1. **查询语言*...

    asp_搜索引擎介绍

    在ASP中,可以通过在网页中嵌入这些搜索引擎的搜索表单,通过GET方法提交查询请求。例如,对于Google,我们可以创建一个HTML表单,设置action属性指向Google的搜索URL,并添加隐藏字段来指定搜索范围(即网站地址)...

    asp.net搜索引擎源码完整版

    ASP.NET搜索引擎源码完整版是一款基于微软的ASP.NET技术开发的搜索引擎系统,它为开发者提供了一个在Web环境中构建高效、可定制的搜索解决方案的基础。这个系统不仅具备基本的索引和搜索功能,还特别强调了在虚拟...

    自动搜索(如百度搜索)asp.net应用

    在本案例中,我们将探讨如何在ASP.NET应用中实现类似百度首页的自动搜索功能。 首先,我们要理解ASP.NET是什么。ASP.NET是由微软开发的一种Web应用程序框架,用于构建动态网站、Web应用和Web服务。它提供了丰富的...

    asp新闻发布及站内搜索

    2. 搜索逻辑:在ASP页面中,获取表单提交的关键词,然后构造SQL查询语句,使用LIKE或全文索引进行模糊匹配。例如,`SELECT * FROM news WHERE title LIKE '%关键词%'`,查找标题中包含关键词的新闻。 3. 结果展示:...

    复杂的搜索页面(asp.net源代码)

    - 对于初学者,这个例子展示了如何在ASP.NET环境中建立一个完整的搜索系统,涵盖了数据库交互、用户界面设计和事件驱动编程的基本概念。 - 通过阅读和理解源代码,开发者可以学习如何使用C#语言与ASP.NET Web ...

    asp+access实现的简单的搜索引擎

    2. 数据库连接:在ASP中,可以使用ADODB(ActiveX Data Objects Database)连接和操作Access数据库,例如建立Connection对象,执行SQL语句。 三、搜索引擎核心原理 1. 检索引擎:搜索引擎的核心是检索引擎,它负责...

    基于asp的搜索引擎开发(源代码+毕设文档).zip

    在这个项目中,我们将深入探讨ASP(Active Server Pages)技术在构建网页搜索引擎中的应用,以及相关的重要知识点。 一、ASP基础 ASP是微软公司推出的一种服务器端脚本环境,用于生成动态网页。它允许开发者使用...

    搜索引擎ASP.NET

    在这个主题中,我们将深入探讨如何利用ASP.NET的技术特性来设计和实现一个功能完善的搜索引擎。 首先,搜索引擎的核心组成部分包括数据抓取、索引建立、查询处理和结果展示等环节。在ASP.NET环境下,我们可以使用C#...

    ASP实例开发源码——百度视频搜索程序asp版.zip

    3. **SQL查询**:在ASP中,通过Command对象执行SQL语句来搜索视频数据。这可能涉及到对视频标题、描述、作者等字段的匹配。SQL的SELECT语句通常用于检索数据,WHERE子句用于设定搜索条件。 4. **结果展示**:查询...

    ASP源码—搜索动力(ASP+access) 正式版.zip

    在"搜索动力"这个项目中,ASP与Access数据库结合使用,提供了一个功能强大的搜索解决方案。Access是一种关系型数据库管理系统,常用于小型到中型的应用,因其易于使用和良好的与Office套件集成而受到欢迎。在ASP中,...

Global site tag (gtag.js) - Google Analytics