基于ASP的站内多值搜索(5)

2008-02-23 05:31:12来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


Web搜索界面如下:

姓名:
电话:
学校:
搜索按钮


采用枚举法的源程序如下:
<%@ CODEPAGE = "936" %>
'连接数据库
<%
dim conn
dim DBOath
dim rs
dim sql
Set conn=Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("addressbook.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
Set rs=Server.CreateObject("ADODB.Recordset")
'从Web页获取姓名、电话、学校的值
dim Name
dim Tel
dim School
Name=request("Name")
Tel=request("Tel")
School=request("School")
'枚举法的搜索核心,因为有3个条件所以要写8组If判断语句
if trim(Name)="" and trim(Tel)="" and trim(School)="" then
sql="select * from address order by ID asc"
end if
if trim(Name)="" and trim(Tel)="" and trim(School)<>"" then
sql="select * from address where School like '%"&trim(School)&"%' order by ID asc"
end if
if trim(Name)="" and trim(Tel)<>"" and trim(School)="" then
sql="select * from address where Tel like '%"&trim(Tel)&"%' order by ID asc"
end if
if trim(Name)="" and trim(Tel)<>"" and trim(School)<>"" then
sql="select * from address where Tel like '%"&trim(Tel)&"%' and School like '%"&trim(School)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)="" and trim(School)="" then
sql="select * from address where Name like '%"&trim(Name)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)="" and trim(School)<>"" then
sql="select * from address where Name like '%"&trim(Name)&"%' and School like '%"&trim(School)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)<>"" and trim(School)="" then
sql="select * from address where Name like '%"&trim(Name)&"%' and Tel like '%"&trim(Tel)&"%' order by ID asc"
end if
if trim(Name)<>"" and trim(Tel)<>"" and trim(School)<>"" then
sql="select * from address where Name like '%"&trim(Name)&"%' and Tel like '%"&trim(Tel)&"%' and School like '%"&trim(School)&"%' order by ID asc"
end if
rs.open sql,conn,1,1
'显示搜索结果
if rs.eof and rs.bof then
response.write "目前通讯录中没有记录"
else
do while not rs.eof
response.write "姓名:"&rs("Name")&"电话:"&rs("Tel")&"学校:"&rs("School")&"<br>"
rs.movenext
loop

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:用PreRender解决DataGrid分页最后一页行数不满的排版问题

下一篇:XLS与MDB文件格式互换全攻略