fifaonline3绝版卡名单:asp动态网页问题?

来源:百度文库 编辑:高考问答 时间:2024/05/07 03:02:02
如何在一个网页中实现搜索功能呀?如果能给出相应的代码就最好了.请各位高手指教.

另一文件,放在<body></body>中:

<form action="search.asp" method="get">
<input type="text" name="key" onClick="javascript:if(this.value=='请输入关键字')this.value='';" value="请输入关键字" size="21" class="input"><br>
<input type="radio" name="searchtype" value="title" checked>标题
<input type="radio" name="searchtype" value="content">内容
<input type="submit" name="s2" value="搜 索">
</form>

search.asp:
<!--#include file="conn.asp"-->'连接数据库的文件
<%
key=request("key")
searchtype=request("searchtype")
if key="" then
response.write "<script>alert('查找字符串不能为空!');history.back();</Script>"
response.end
end if
%>
<%
Set rs= Server.CreateObject("ADODB.Recordset")
if searchtype="title" then
sql="select * from wenzhang where title Like '%"& key &"%' order by id desc"
elseif searchtype="content" then
sql="select * from wenzhang where content Like '%"& key &"%' order by id desc"
else
end if
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p align='center'>对不起,没有找到相关内容</p>"
else
%>
<%
i=0
do while not rs.eof
%>

<%=rs("id")%>
<a href="articleshow.asp?id=<%=rs("id")%>" <%=rs("title")%></a>
=rs("fartime")%>
=rs("hits")%>
<%
rs.movenext
i=i+1
loop
%>
共找到包含关键字<%=i%>
<%
end if
rs.close
set rs=nothing
%>

strsql="select * from 表名 where 字段名 like %关键字%"

这样就可以的啦.

代码很复杂,不是写出来你就可以理解的,如果你能自己写搜索和文件上传,说明你的aso 就不错了,建议自己去下载一个有搜索、上传功能的 asp 源代码,然后自己研究以下,学着修改等等。
注意:要溯源,了解每段代码的真正用途,不要简单的实现功能就满足,学习别人的编程思想。思想很重要!~