Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->ASP ->正文

基于ASP的站内多值搜索

来源:Linuxdby.com 作者:Webmaster 时间:2007-04-24 点击: [收藏] [投稿]
  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
end if
'断开数据库
set rs=nothing        
  conn.close     
  set conn=nothing
%>



理解上述程序时,着重琢磨核心部分,8组语句一一对应了3个搜索框中的8种状态

Name
Tel
School
非空
非空
非空
非空
非空


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:用PreRender解决DataGrid分页最后一页行数不满的排版问题   下一篇:XLS与MDB文件格式互换全攻略

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章