ASP Classic - 如何计算嵌套列表中的子项数

时间:2012-11-15 15:55:20

标签: asp-classic vbscript

我有一个嵌套列表,用于显示分别在各自标题下分组的数据库中的可用视频。 我想知道是否可以计算每个分组中的视频数量,以便我可以这样显示:

视频组标题1(3个视频)
1.视频1
2.视频2
3.视频3
视频组标题2(6视频)
1.视频1
2.视频2
...等

SQL现在非常简单:

SELECT * FROM video_module_type;

我正在使用ASP VBscript,而我所拥有的代码是:

<%
'----------------------------------------------------------------------------------------------------
    'VARIABLES
'----------------------------------------------------------------------------------------------------

Dim previous_video_module_name
Dim first_video_module_name
Dim DIV_vms_vid_title
Dim DIV_vms_grouping
Dim DIV_video_section_group
Dim DIV_vms_video_holder
Dim DIV_vms_sm_thumb
Dim DIV_vms_results
Dim vms_shim
Dim DIV_end

previous_video_module_name = ""
first_video_module_name = true

DIV_vms_vid_title = "<div class=""vms_vid_title"">"
DIV_vms_grouping = "<div id=""sustvid_webinar"" class=""vms_grouping"">"
DIV_video_section_group = "<div class=""video_section_group"">"
DIV_vms_video_holder = "<div class=""vms_video_holder"">"
DIV_vms_sm_thumb = "<div class=""vms_sm_thumb"">"
DIV_vms_vid_synopsis = "<div class=""vms_vid_synopsis"">"
DIV_vms_results = "<div class=""vms_results"">"
vms_shim = "<img src=""/images/shim.gif"" width=""16"" height=""16"">"
DIV_end = "</div>"
'----------------------------------------------------------------------------------------------------
    'IF NOT THE SAME VALUE AS PREVIOUS
'----------------------------------------------------------------------------------------------------
for i = 0 to videoModulesListerNumber-1

    if video_module_name(i) <> previous_video_module_name then
        '------------------------------------------------------------------------------------------
            'IF NOT THE FIRST TIME, CLOSE THE NESTED LIST
        '------------------------------------------------------------------------------------------
            if first_video_module_name then
              response.Write("<h2>" & video_module_name(i) & "</h2>")
            end if
        '------------------------------------------------------------------------------------------
            'DISPLAY THE CATEGORY
        '------------------------------------------------------------------------------------------
        response.Write("<!--START VIDEO GROUP: " & video_module_name(i) & "-->")
        '------------------------------------------------------------------------------------------
            'IF NOT THE SAME VALUE AS PREVIOUS OPEN THE NESTED LIST AND STORE THE CURRENT 
            'VALUE FOR COMPARISON NEXT TIME
        '------------------------------------------------------------------------------------------
        previous_video_module_name = video_module_name(i)
    end if
    '------------------------------------------------------------------------------------------
    'DISPLAY THE VIDEOS 
    '------------------------------------------------------------------------------------------
    response.Write(DIV_vms_grouping)
    response.Write(DIV_video_section_group)
    response.Write(DIV_vms_video_holder)
    response.Write(DIV_vms_vid_title & "<h2>" & video_module_video_name(i) & "</h2>" & DIV_end)
    response.Write(DIV_vms_sm_thumb & video_module_thumbnail(i) & DIV_end)
    response.Write(DIV_vms_vid_synopsis)
    response.Write("<p>" & video_module_synopsis(i) & "</p>")
    response.Write(DIV_vms_results & vms_shim & DIV_end)
    response.Write(DIV_end) ' close DIV_vms_grouping
    response.Write(DIV_end) ' close DIV_video_section_group
    response.Write(DIV_end) ' close DIV_vms_video_holder
    '------------------------------------------------------------------------------------------
        'IT'S NO LONGER THE FIRST TIME; CHANGE THE "first_video_module_name" VARIABLE
    '------------------------------------------------------------------------------------------
    first_video_module_name = false
next

%>

我认为问题可能是我不知道这个术语是什么,所以我无法搜索它,但任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

您可以将查询更改为

SELECT video_module_type.*, (SELECT COUNT(*) 
                             FROM video_module_type as t2 
                             WHERE t2.Group = video_module_type.VideoGroup) as GroupCount 
FROM video_module_type

并使用GroupCount字段。

您可以两次遍历结果,第一次计算项目,第二次显示结果

您可以使用Javascript计算项目并显示结果 ->JsFiddle Example