+ -
当前位置:首页 → 问答吧 → 根据id查询出信息再跟查询的信息去查询内容

根据id查询出信息再跟查询的信息去查询内容

时间:2011-06-10

来源:互联网

表名字:abc
字段名: id chengshi name 
字段数据:id: 1,chengshi:成都市 ,name:张三
字段数据:id: 2,chengshi:成都市 ,name:李四
字段数据:id: 3,chengshi:成都市 ,name:赵二
字段数据:id: 4,chengshi:北京市 ,name:王当
字段数据:id: 5,chengshi:北京市 ,name:邱雨
字段数据:id: 6,chengshi:天津市 ,name:何东
字段数据:id: 7,chengshi:天津市 ,name:张四
字段数据:id: 8,chengshi:天津市 ,name:张五
字段数据:id: 9,chengshi:成都市 ,name:张六
字段数据:id: 10,chengshi:成都市 ,name:张七
数据库假设有这么10条信息
 现在我第一步假设id=2根据ID读取信息应该是 id 2 城市:成都市 姓名:李四
第一段代码根据传递id过来的代码<% 
id=request.QueryString("id")
if id="" or not isnumeric(id) then
Response.Write "<script>alert('参数错误!');history.go(-1);</script>" 
Response.End()
end if
exec="select * from abc where id="&id
set rs=server.createobject("adodb.recordset") 
rs.open exec,conn,1,1 
if rs.eof and rs.bof then
Response.Write "<script>alert('参数不正确,ID值不存在!');history.go(-1);</script>" 
Response.End()
end if
%>

上面第一步玩; 下面做最重要我不懂的问题了 
此处一万字没时间写
呵呵上面玩笑了哪有什么字
 说重点上面我们不是根据ID查询出第2条记录了(id 2 城市:成都市 姓名:李四
)现在我们要根据这条记录的城市名称查询出这个城市的人员名字
sql1 = "select * from [abc] where chengshi="&rs("chengshi")&" order by id desc"
set rs1=server.createobject("adodb.recordset")
rs1.open exec,conn,1,1 
if rs1.eof and rs1.bof then
Response.Write "<script>alert('参数不正确,ID值不存在!');history.go(-1);</script>" 
Response.End()
end if
%> <%=rs1("name")%>
就应该是 城市:成都市, 姓名:张三

  城市:成都市 ,姓名:李四
  城市:成都市 ,姓名:赵二
  城市:成都市 ,姓名:张六
  城市:成都市 ,姓名:张七 

请高手们指点一万字内容

作者: wutengchu   发布时间: 2011-06-10

同志们辛苦你们了

作者: wutengchu   发布时间: 2011-06-10

这个很简单嘛,一条查询语句就搞定了,何必弄那么复杂
exec="select * from [abc] where chengshi=(select chengshi from [abc] where id="&id
&")"

作者: lzp4881   发布时间: 2011-06-10

好像不行出不来数据

作者: wutengchu   发布时间: 2011-06-10

出来的数据只是当条数据

作者: wutengchu   发布时间: 2011-06-10