注册 登录
编程论坛 ASP技术论坛

麻烦帮忙看一下这代码

sydpoechang 发布于 2008-01-10 15:51, 2249 次点击
id=Request.Querystring("id")
session("id")=id
sql="select * from gczb where id="&id
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,1
if rs.eof then
     Response.Write("没有相关内容")
     Response.end
  end if
  sql2="select * from gztb where JaAdmin='"&session("JaAdmin")&"' and UserID="&id
  set rs2=server.createobject("adodb.recordset")
  rs2.open sql2,conn1,1,1
  session("shenc")=rs2("shenc")
  session("JaAdmin1")=rs2("JaAdmin")
  session("UserID")=rs2("UserID")

<% if session("shenc")=1 and session("JaAdmin")=session("JaAdmin1") and session("id")=session("UserID") then %>
<%=rs("gcadd")%>
<%else%>
<% Response.Write "装饰公司高级会员投标审查后才可以看" %>
<%end if%>

说明:
id为所看页面的id号
JaAdmin和JaAdmin1用户名
<%Response.Write session("JaAdmin1")%>
<%Response.Write session("JaAdmin")%>
<%Response.Write session("id")%>
<%Response.Write session("UserID")%>
都能输出相对应的值
<% if session("shenc")=1 and session("JaAdmin")=session("JaAdmin1") and session("id")=session("UserID") then %>这代码中去掉了and session("id")=session("UserID") 可以显示<%=rs("gcadd")%>数据 加上后只能显示"装饰公司高级会员投标审查后才可以看"
22 回复
#2
sydpoechang2008-01-10 16:54
突然发现 UserID和id 不是在一个数据库里的 估计是这个原因 不知道有没有对比两个不同数据库的代码?
#3
madpbpl2008-01-10 21:00
不在一个数据库还是不在一个表里?如果是两个表,表之间有什么联系吗?
#4
sydpoechang2008-01-11 12:33
现在弄成一个数据库不同表了
现如有两个表A、B
表中的B表中的UserID(有自己的自动编号)是A表中id(A中的自动编号)
现在的问题还是
<% if session("shenc")=1 and session("JaAdmin")=session("JaAdmin1") and session("id")=session("UserID") then %>这代码中去掉了and session("id")=session("UserID") 可以显示<%=rs("gcadd")%>数据 加上后只能显示"装饰公司高级会员投标审查后才可以看"

但是
<%Response.Write session("id")%>(自动编号 数字型吧)
<%Response.Write session("UserID")%> (数字型)
两个输出的值都是一样的 如id输出为1 UserID也输出为1
但是session("id")=session("UserID")  却无法比对
#5
sydpoechang2008-01-11 14:38
达人快来呀~
#6
sydpoechang2008-01-11 21:05
不要沉了呀
#7
gdk20062008-01-12 09:01
想问问你要实现一个什么功能,是要一个审核的功能吗!
“装饰公司高级会员投标审查后才可以看”这个是你的目的吗?
#8
sydpoechang2008-01-12 13:34
审查功能已经实现
这是一个招标启示
客服要求的是 投标人必须经过审查了之后才能看见招标的部分内容
通过了审查的客服 可以看见<%=rs("gcadd")%>这个值
没通过的就显示<% Response.Write "装饰公司高级会员投标审查后才可以看" %>
#9
wigal2008-01-12 14:54
sql2="select * from gztb where JaAdmin='"&session("JaAdmin")&"' and UserID="&id and gztb.userid=gztc.id

[[italic] 本帖最后由 wigal 于 2008-1-12 14:55 编辑 [/italic]]
#10
sydpoechang2008-01-12 15:11
楼上的兄弟 那样写无效
#11
madpbpl2008-01-12 15:36
试试这样行不行,如果行,把你的程序里的response.end去掉(其他按你的源代码)试试
if rs.eof and rs.bof then
     Response.Write("没有相关内容")
  else
  sql2="select * from gztb where JaAdmin='"&session("JaAdmin")&"' and UserID="&id
  set rs2=server.createobject("adodb.recordset")
  rs2.open sql2,conn1,1,1
  session("shenc")=rs2("shenc")
  session("JaAdmin1")=rs2("JaAdmin")
  session("UserID")=rs2("UserID")

<% if session("shenc")=1 and session("JaAdmin")=session("JaAdmin1") and session("id")=session("UserID") then %>
<%=rs("gcadd")%>
<%else%>
<% Response.Write "装饰公司高级会员投标审查后才可以看" %>
<%end if%>
<%end if%>
#12
wigal2008-01-12 16:29
刚才的我sql是错应该是
    sql2="select * from gztb,gczb where JaAdmin='"&session("JaAdmin")&"' and UserID="&id and gztb.userid=gczb.id
      刚才没应用2个表,而且还表名错了列
   不用这个连接的话,session("id")永远不能等于session("userid")
#13
sydpoechang2008-01-12 16:38
回12楼的朋友语法错误 可以这样查找两个表吗?sql2="select * from gztb,gczb
#14
wigal2008-01-12 17:25
当然可以了撒 !?
    如果语法有错误除非是表名啊,字段名 出错的
#15
sydpoechang2008-01-12 17:30
检查出 错误了 但是还是无法对比出来
郁闷 真的怀疑这机子 有问题了
#16
hangxj2008-01-12 17:36
and int(session("id"))=int(session("UserID") )

这样试一下,程序还是按照你原来的
#17
sydpoechang2008-01-12 17:45
谢谢hangxj
#18
hangxj2008-01-12 17:48
不要谢我,首先我要问下你功能实现了没有?
要是实现了,你有没有想过为什么这样可以?
#19
pcx2008-01-13 20:55
加油
#20
sydpoechang2008-01-14 17:31
当时我是这样想的自动编号应该也是数字型而我所对比的也是数字型 应该可以能对比出结果 不知道这样的想发是否正确.
#21
yms1232008-01-14 18:16
and session("id")=session("UserID")
明显这句话的比较结果返回了False结果,因为and逻辑与关系判断有一项表达式为False,IF判断的所有表达式就会都返回False
#22
sydpoechang2008-01-16 12:23
为什么这句会是假的?自动编号应该也是数字型吧 数字比对数字怎么比对不出来?
#23
gdk20062008-01-17 22:03
原帖由 [bold][underline]sydpoechang[/underline][/bold] 于 2008-1-16 12:23 发表 [url=http://bbs.bc-cn.net/redirect.php?goto=findpost&pid=1181572&ptid=196881][/url]
为什么这句会是假的?自动编号应该也是数字型吧 数字比对数字怎么比对不出来?


如果你的两个Session值都是一样的话,那么检查你的数据类型,用Cint(session("id"))=Cint(session("UserID"))看看!

感觉你这样写有些不对!
1