| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 271 人关注过本帖
标题:多重条件查询的问题,老是调不出来
只看楼主 加入收藏
追梦的大海
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-7-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
多重条件查询的问题,老是调不出来
<!--#include file="conn1.asp"-->
<%
'dim simi_title()'定义数组接收相似度的值
'dim simi_course()
'dim simi_location()
'dim simi_collaborator()

dim id()
dim getid()

'接受用户输入
exp_title=request.form("exp_title")
exptitle=Rtrim(Ltrim(exp_title))
exp_title=request.form("exp_title")

exp_course=request.form("exp_course")
expcourse=Rtrim(Ltrim(exp_course))
exp_course=request.form("exp_course")
'
'course_number=request.form("course_number")
'coursenumber=Rtrim(Ltrim(course_number))
'course_number=request.form("course_number")

exp_people=request.form("exp_people")
exppeople=Rtrim(Ltrim(exp_people))
exp_people=request.form("exp_people")

student_number=request.form("student_number")
studentnumber=Rtrim(Ltrim(student_number))
student_number=request.form("student_number")

student_college=request.form("student_college")

student_major=request.form("student_major")
studentmajor=Rtrim(Ltrim(student_major))
student_major=request.form("student_major")

student_grade=request.form("student_grade")

student_class=request.form("student_class")

exp_date=request.form("exp_date")
expdate=Rtrim(Ltrim(exp_date))
exp_date=request.form("exp_date")

exp_location=request.form("exp_location")
explocation=Rtrim(Ltrim(exp_location))
exp_location=request.form("exp_location")

exp_collaborator=request.form("exp_collaborator")
expcollaborator=Rtrim(Ltrim(exp_collaborator))
exp_collaborator=request.form("exp_collaborator")

exp_tutor=request.form("exp_tutor")
exptutor=Rtrim(Ltrim(exp_tutor))
exp_tutor=request.form("exp_tutor")


'====course====
cflag=0
If exp_course<> "" Then
   cflag=1
   csql = "exp_course like '%"&expcourse&"%'"
end if

set crs=server.CreateObject("adodb.recordset")
if cflag<>0 then
   csql="select exp_title from course where "&csql
   crs.open csql,conn,1,1
   do while not crs.eof
   exptitlestr=exptitlestr&"'"&crs("exp_title")&"'"&","
   crs.movenext
   loop
   ccount=crs.recordcount
   crs.close
   set crs=nothing
   if ccount=0 then
     Response.Redirect "kong.asp"
     Response.End
   end if

end if

'====student====
tflag=0
If exp_people<> "" Then
   tflag=1
   tsql = "exp_people like '%"&exppeople&"%'"
end if
If student_college <> "请选择" Then
   if tflag=1  then
   tsql = tsql&" and "&"student_college like '%"&student_college&"%'"
   else
   tflag=1
   tsql = "student_college like '%"&student_college&"%'"
   end if
end if
If student_major <> "" Then
   if tflag=1  then
   tsql = tsql& " and "&"student_major like '%"&studentmajor&"%'"
   else
   tflag=1
   tsql = "student_major like '%"&studentmajor&"%'"
   end if
end if
If student_grade <> "请选择" Then
   if tflag=1  then
   tsql = tsql&" and "&"student_grade like "&student_grade &""
   else
   tflag=1
   tsql = "student_grade like "&student_grade&""
   end if
end if
If student_class <> "请选择" Then
   if tflag=1  then
   tsql = tsql&" and "&"student_class like "&student_class &""
   else
   tflag=1
   tsql = "student_class like "&student_class&""
   end if
end if

set trs=server.CreateObject("adodb.recordset")
if tflag<>0 then
   tsql="select student_number from student where "&tsql
   trs.open tsql,conn,1,1
   do while not trs.eof
   studentnumberstr=studentnumberstr&"'"&trs("student_number")&"'"&","
   trs.movenext
   loop
   tcount=trs.recordcount
   trs.close
   set trs=nothing
   if tcount=0 then
     Response.Redirect "kong.asp"
     Response.End
   end if
end if

'====baogao====
flag=0
If student_number<> "" Then
   flag=1
   ssql = "student_number like "&studentnumber
end if
If exp_date <> "" Then
   if flag=1  then
   ssql = ssql&" and "&"exp_date like '%"&expdate&"%'"
   else
   flag=1
   ssql = "exp_date like '%"&expdate&"%'"
   end if
end if
'If exp_collaborator <> "" Then
'   if flag=1  then
'   ssql = ssql&" and "&"exp_collaborator like '%"&expcollaborator&"%'"
'   else
'   flag=1
'   ssql = "exp_collaborator like '%"&expcollaborator&"%'"
'   end if
'end if
If exp_tutor <> "" Then
   if flag=1  then
   ssql = ssql&" and "&"exp_tutor like '%"&exptutor&"%'"
   else
   flag=1
   ssql = "exp_tutor like '%"&exptutor&"%'"
   end if
end if
'If exp_teacher <> "" Then
'   if flag=1  then
'   ssql = ssql&" and "&"exp_teacher like '%"&expteacher&"%'"
'   else
'   flag=1
'   ssql = "exp_teacher like '%"&expteacher&"%'"
'   end if
'end if

set rs=server.CreateObject("adodb.recordset")
if cflag=0 and tflag=0 and flag=0 then
   sql="select * from baogao order by exp_number"
   rs.open sql,conn,1,1
end if
if cflag=0 and tflag=0 and flag<>0 then
   ssql="select * from baogao where "&ssql&" order by exp_number"
   rs.open ssql,conn,1,1
end if
if cflag=0 and tflag<>0 and flag=0 then
   sql="select * from baogao where student_number in ("&studentnumberstr&") order by exp_number"
   rs.open sql,conn,1,1
end if  
if cflag=0 and tflag<>0 and flag<>0 then
   ssql="select * from baogao where "&ssql&" and student_number in ("&studentnumberstr&") order by exp_number"
   rs.open ssql,conn,1,1
end if  
if cflag<>0 and tflag=0 and flag=0 then
   sql="select * from baogao where exp_title in ("&exptitlestr&") order by exp_number"
   rs.open sql,conn,1,1
end if
if cflag<>0 and tflag=0 and flag<>0 then
   ssql="select * from baogao where "&ssql&" and exp_title in ("&exptitlestr&") order by exp_number"
   rs.open ssql,conn,1,1
end if
if cflag<>0 and tflag<>0 and flag=0 then
   sql="select * from baogao where exp_title in ("&exptitlestr&") and student_number in ("&studentnumberstr&") order by exp_number"
   rs.open sql,conn,1,1
end if
if cflag<>0 and tflag<>0 and flag<>0 then
   ssql="select * from baogao where "&ssql&" and exp_title in ("&exptitlestr&") and student_number in ("&studentnumberstr&") order by exp_number"
   rs.open ssql,conn,1,1
end if
sumrecord=rs.recordcount

'====显示结果====
dim recordct
if exp_title="" and exp_location="" then
    set rs=server.CreateObject("adodb.recordset")
    if flag=0 then
       rs.open sql,conn,1,1
       recordct=rs.recordcount
    else
       rs.open ssql,conn,1,3
       recordct=rs.recordcount
    end if
    if recordct=0 then
       Response.Redirect "kong.asp"
       Response.End
    end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>传播学院实验报告管理系统_检索结果</title>
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    background-image: url(images/di.gif);
}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images/searesult.gif" width="780" height="135"></td>
  </tr>
</table>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="18" bgcolor="0150A9" class="white" align="right">当前共查询到[<font class="white"><%=recordct%></font>]条记录</td>
  </tr>
</table>
  <%dim n
  n=1
  do while not rs.eof%>
 <table width="780" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="D5EEFE">
  <tr>
    <td width="50" height="25" align="center"><img src="images/book.gif" width="22" height="24"></td>
    <td width="65" height="25" class="up">实验名称:</td>
    <td height="25" class="up"><font class="up"><%=dropkong(rs("exp_title"))%></font></td>
    <td height="25" colspan="2" class="up" align="right">
    <%path=rs("path")
    if len(path)>0 then%>
    <font class="up"><a href="<%=path%>" target="_blank">原始报告</a></font>
    <%end if
    pathyiyue=rs("pathyiyue")
    if len(pathyiyue)>0 then%>
    <font class="up"><a href="<%=pathyiyue%>" target="_blank">已阅报告</a></font>
    <%end if%>
    </td>
  </tr>
<%
dqexptitle=rs("exp_title")
set ccrs=server.CreateObject("adodb.recordset")
ccsql="select * from course where exp_title like '"&dqexptitle&"'"
ccrs.open ccsql,conn,1,1
%>
  <tr>
    <td height="25">&nbsp;</td>
    <td width="65" height="25" class="up">实验课程:</td>
    <td width="300" height="25" class="up"><%=ccrs("exp_course")%></td>
   
  <%
ccrs.close
set ccrs=nothing
%>
<td width="65" height="25" class="up">指导教师:</td>
    <td width="300" height="25" class="up"><%=rs("exp_tutor")%></td>
  </tr><%
dqstudentnumber=rs("student_number")
set ttrs=server.CreateObject("adodb.recordset")
ttsql="select * from student where student_number like "&dqstudentnumber
ttrs.open ttsql,conn,1,1
%>
  <tr>
    <td height="25">&nbsp;</td>
    <td height="25" class="up">实 验 人:</td>
    <td height="25" class="up"><%=ttrs("exp_student")%></td>
    <td height="25" class="up">学  号:</td>
    <td height="25" class="up"><%=rs("student_number")%></td>
  </tr>
  <tr>
    <td height="25">&nbsp;</td>
    <td height="25" class="up">学院专业:</td>
    <td height="25" class="up"><%=ttrs("student_college")%><%=ttrs("student_major")%></td>
    <td height="25" class="up">班  级:</td>
    <td height="25" class="up"><%=ttrs("student_grade")%>级<%=ttrs("student_class")%>班</td>
  </tr>
  <%
ttrs.close
set ttrs=nothing
%>
   <tr>
    <td height="25">&nbsp;</td>
    <td height="25" class="up">实验地点:</td>
    <td height="25" class="up"><%=dropkong(rs("exp_location"))%></td>
    <td height="25" class="up">实验日期:</td>
    <td height="25" class="up"><%=rs("exp_date")%></td>
  </tr>
  
  
  <tr>
    <td colspan="5"><img src="images/dotline.gif" width="780" height="4"></td>
  </tr>
 </table>

<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="35" bgcolor="0150A9" align="center"><span class="white">传媒学院版权所有</span></td>
  </tr>
</table>
</body>
</html>
搜索更多相关主题的帖子: include file 用户 
2011-07-08 18:08
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:20 
这么多代码,也不说明白是哪一句出了问题,谁会一句一句帮你看?

----我怎能在别人的苦难面前转过脸去----
2011-07-09 08:34
快速回复:多重条件查询的问题,老是调不出来
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039251 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved