Classic ASP中独特的多维数组

时间:2015-09-23 10:12:46

标签: arrays asp-classic active-directory

我正在尝试使用ASP Classic生成组织结构图。我正在处理的代码使用单个LDAP查询来获取性能以获取所有信息。我有以下代码:

 <%@ Language="VBScript"%>
 <% response.Buffer = True
 dim ADUser 'Holds the OU
 dim RecordList 'Holds the RecordList object
 %>
 <html>
 <head>
 <link rel="stylesheet" href="../style.css">
 </head>
 <body>
 <!--#include virtual="//includes/functions.asp"-->
 <!--#include virtual="//includes/display.asp"-->
 <h1>Organisational Structure</h1>
 <div class="commandspace">
 <p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
 </div>
 <% 
 ADUser = "LDAP://OU=Staff,OU=Users,DC=company,DC=internal"
 ' Make AD connection and run query
 Set objCon = Server.CreateObject("ADODB.Connection")
 objCon.provider ="ADsDSOObject"
 objCon.Properties("User ID") = "EXAMPLE\User"
 objCon.Properties("Password") = "PaSsWoRd"
 objCon.Properties("Encrypt Password") = TRUE
 objCon.open "Active Directory Provider"
 Set objCom = CreateObject("ADODB.Command")
 Set objCom.ActiveConnection = objCon
 objCom.CommandText ="select company, department, givenName, sn, title, telephoneNumber FROM '"& ADUser &"' where company ='*'" 
 Set objRS = objCom.Execute
 RecordList = objRS.GetRows()
 ' Loop over returned recordset and output HTML
 for i = 0 to uBound(RecordList, 2)
      u = i + 1
      if RecordList(5,i) <> RecordList(5,u) then
           Response.Write "<div class='Structure_Item_1'>" & RecordList(5,i) & "</div>" & vbCrLf
      end if
      if RecordList(4,i) <> RecordList(4,u) then
           Response.Write "<div class='Structure_Item_2'>" & RecordList(4,i) & "</div>" & vbCrLf
      end if
      Response.Write  "<div class='Structure_Item_3'>" & RecordList(3,i) & " " & RecordList(2,i) & "</div>" &vbCrLf
 next
 objRS.Close
 objCon.Close
 Set objRS = Nothing
 Set objCon = Nothing
 Set objCom = Nothing
 %>
 </body>
 </html>

该页面将列出部门内的不同服务区域,部门和人员。我的问题是我得到重复的数据。

我已经考虑过将这些部门放在脚本词典中但是意识到它不会起作用,因为它不会是多维的,所以我不能将服务区和部门放在同一个字典中除非我将服务区域设置为关键,将部门设置为值。

然而,这意味着密钥不是唯一的。部门和工作人员的姓名也是如此。

我在考虑两个阵列,一个是服务区域和部门,一个是部门和员工名称。那时我打算做一个比较操作来决定格式

非常感谢帮助。我担心这会让我的头脑更有意义

1 个答案:

答案 0 :(得分:0)

这要么是我完全忽略了你的观点,要么你错过了森林的树木,但是如果你每次特定的栏目发生变化时都要写出标题,你需要确保“按该列排序。否则,您将在随机位置重复标题。如果需要多个标题级别,请按优先级的降序对相应列进行排序。

(旁注:您可能希望在执行.Getrows后立即关闭记录集,然后然后开始编写数据。否则,您可能还没有使用了Getrows。)