关于多条件精确匹配查询

anxl 2003-09-30 08:36:28
初学ASP 大家多指教谢谢!多条件精确匹配查询这样写对吗?为什么
查询页定义from 依次为“jm”“jx”“nd”“js”要求查询结果为:jm加jx加nd加js,每个from可为空
<%
dim conn
on error resume next
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "dsn=lxd;uid=;pwd=;"
%>
<%
const MaxPerPage=20
dim totalPut
dim category
dim CurrentPage
dim TotalPages
dim i
dim filename
dim categoryid
jm = request.form("jm")
jx =request.form("jx")
nd = request.form("nd")
js = request.form("js")
%>
<%
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
filename="yphj_search.asp"
dim sql
dim rs
sql = "select lxzlt.zlno as lzlno,lxzlt.Name as orname, lxzlt.Cname as Cname, lxzlt.Director as Director, lxzlt.content as content, lxzlt.hints as hints, lxzlt.lang as lang, lxzlt.minutes as minutes, lxzlt.kinds as kinds,lxzlt.Counts as Counts from lxzlt inner join prize on lxzlt.zlno = prize.zlno where prize.Prize like '%"&jm&"%' and prize.kind like '%"&jx&"%' and prize.Pyear like '%"&nd&"%' and prize.Parray like '%"&js&"%' order by lxzlt.zlno asc"

Set RS = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,3,1
...全文
84 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
anxl 2003-09-30
  • 打赏
  • 举报
回复
诚恳等待
anxl 2003-09-30
  • 打赏
  • 举报
回复
查询可以实现只是分页时出问题?
<%
function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
response.write "<p align=center><form method=Post action="&filename&"?jm="&jm&"&jx="&jx&"&nd="&nd&"&js="&js&">"
if CurrentPage<2 then
response.write "<font color='999966'>首页   上一页</font>   "
else
response.write "<a href="&filename&"?jm="&jm&"&jx="&jx&"&nd="&nd&"&js="&js&">首页</a>   "
response.write "<a href="&filename&"?page="¤tPage-1&"&jm="&jm&"&jx="&jx&"&nd="&nd&"&js="&js&">上一页</a>   "
end if
if n-currentpage<1 then
response.write "<font color='999966'>下一页   尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)&"&jm="&jm&"&jx="&jx&"&nd="&nd&"&js="&js&">下一页</a>  "
response.write " <a href="&filename&"?page="&n&"&jm="&jm&"&jx="&jx&"&nd="&nd&"&js="&js&">尾页</a>"
end if
response.write "  <font color=red>"¤tPage&"</font>/"&n&" 页 "
response.write " 总共 <font color=red><b>"&totalnumber&"</b></font> 个"
response.write " 转到第 <input type='text' name='page' size=2 maxlength=10 class=smallInput value="¤tpage&">"
response.write " 页 <input class=buttonface type='submit' value='Go' name='cmdok'></span></p></form>"

end function
%>
anxl 2003-09-30
  • 打赏
  • 举报
回复
谁能解释以下以下代码的意思吗?我真够菜的!
if jm <> "" and jx = "" then
condition = "prize.PRIZE like '%" & jm & "%'"
end if
if jx <> "" and jm = "" then
condition = "prize.KIND like '%" & jx & "%'"
end if
if jm <> "" and jx <> "" then
condition = "prize.PRIZE ='" & jm & "' and prize.KIND ='" & jx & "'"
end if
if jm = "" and jx = "" then
condition = "false"
end if

if condition <> "false" then
if nd <> "" then
condition = condition & " and prize.PYEAR =" & Cint(nd)
end if

if js <> "" then
condition = condition & " and prize.Parray =" & Cint(js)
end if

else
if nd <> "" then
condition = " prize.PYEAR =" & Cint(nd)
end if
if js <> "" and condition = "false" then
condition = " prize.Parray =" & Cint(js)
else
if js <> "" then
condition = condition & " prize.Parray =" & Cint(js)
end if
end if
end if
ren791123 2003-09-30
  • 打赏
  • 举报
回复
建议你这种情况,最好采取拼串的方法,将所有要查询的拼成一个串,再对串用数组处理就出错的机率就小了
不老书生 2003-09-30
  • 打赏
  • 举报
回复
sql = "select lxzlt.zlno as lzlno,lxzlt.Name as orname, lxzlt.Cname as Cname, lxzlt.Director as Director, lxzlt.content as content, lxzlt.hints as hints, lxzlt.lang as lang, lxzlt.minutes as minutes, lxzlt.kinds as kinds,lxzlt.Counts as Counts from lxzlt inner join prize on lxzlt.zlno = prize.zlno where prize.Prize like '%"&jm&"%' and prize.kind like '%"&jx&"%' and prize.Pyear like '%"&nd&"%' and prize.Parray like '%"&js&"%' order by lxzlt.zlno asc"


sql语句没有明显错误,response.write 出来看能执行吗?不过你可以直接
sql = "select lxzlt.* from lxzlt inner join prize on lxzlt.zlno = prize.zlno where prize.Prize like '%"&jm&"%' and prize.kind like '%"&jx&"%' and prize.Pyear like '%"&nd&"%' and prize.Parray like '%"&js&"%' order by lxzlt.zlno asc"
anxl 2003-09-30
  • 打赏
  • 举报
回复
谢谢楼上!
因为帖子限制我只贴出部分代码只想大家帮忙看一下查询语句的写法可以实现匹配查询吗?
zxmout 2003-09-30
  • 打赏
  • 举报
回复
先建立recorder对象呀!明显错误,没有什么提示吗?
anxl 2003-09-30
  • 打赏
  • 举报
回复
大家帮忙看一下

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧