Home > Articles

  • Print
  • + Share This

Finally, the HTML

As a final step, we have to generate the HTML that draws the book list in your browser. For that we return to GenericMyInformit_Display_HTML, to which we have passed our recordset.

1  If Not l_product_group_id = "" Then
2   pc_group_specifier = l_product_group_id
3  Else
4   pc_group_specifier = l_product_group_name
5  End If
6
7  If Not Request.QueryString("mi_pc_start") = "" Then
8   pc_start = cint(Request.QueryString("mi_pc_start"))
9  Else
10   pc_start = 0
11 End If
12
13 If l_number_of_results_available <
14    pc_start + l_number_of_results_to_display Then
15   pc_num = l_number_of_results_available
16 Else
17   pc_num = pc_start + l_number_of_results_to_display
18 End If
19
20 more_url = Request.ServerVariables("URL") & _
21        "?mi_pc_start=" & _
22        pc_num & _
23        "&mi_pc_count=" & l_number_of_more_results & _
24        "&mi_pc_group=" & _
25        server.URLEncode( pc_group_specifier ) & _
26        "&"

I've skipped down to the section of the function that determines which records to display. To avoid showing a vast list of products on a single page, we chunk them up into more manageable sizes. We keep track of this on the query string. If you're on the MyInformIT front page, the query string won't contain the variable mi_pc_start, so the starting record counter is set to 0 on line 10. If you have 10 books saved, as I do in Figure 1, you'll see that the 10 acts as a "more" link to view the rest. If you click the "more" link to see the rest of your books (or articles), mi_pc_start comes into play. "More" on that shortly.

On lines 13–18 we figure out whether the total number of records (returned from the stored procedure, natch) is more than the maximum number to display. If not, we show them all. If there are too many, we set a chunk size, pc_num. Then we set the variable more_url equal to the URL you would click to see the rest of the results in this category (pc_group_specifier on line 25 is set to the product_group_name or product_group_id on lines 1–5, which, in this case, equals product_group_name Books). Notice that more_url contains a reference to mi_pc_count.

27 l_dsProducts.Move(pc_start)
28
29 %>
30 <table width="100%" border="0" cellspacing="0"
       cellpadding="1">  (...)

On line 27, we set the index of the recordset to the first record we want to display. We then break out of VBScript on line 29 and begin the HTML to display the actual MyInformIT book list. I'll skip over most of this. If you're interested, a "view source" will show you the whole enchilada. Instead, let's scan the loop that draws the actual product list, tucked away inside the HTML:

31 <% For current_result_number = pc_start To pc_num-1 %>
32 <%
33   if l_dsProducts("element_id") <> "" then
34    Earl = "content/index.asp?product_id=" & _
35        l_dsProducts("product_id") & _
36       "&element_id=" & l_dsProducts("element_id")
37    prod_name = l_dsProducts("element_name")
38   else
39    Earl = "content/index.asp?product_id=" & _
40        l_dsProducts("product_id")
41    prod_name = l_dsProducts("product_name")
42   end if

After setting up a loop over the number of results that we want to display (line 31), we ask the question, "Is this a simple product or a certain page of an article?" If the query string contains an element_id, we have an article page. The cheekily and phonetically named Earl stores the URL for viewing the actual content page. We have to include both a product_id and element_id, if on hand, to get to the correct place. The product name is also set in the variable prod_name to either the recordset field, product_name, or the field, element_name.

43   if (l_dsProducts("product_group_name") = "Books") and _
44    (l_dsProducts("free_IT_library_flag") = 1) then
45    product_url = calculateURLCustom(Earl, _
46      "{507A820E-8A4A-477F-800E-5126B7347DC2}",null,
       null,l_dsProducts("product_id") )
47   elseif l_dsProducts("product_group_name") = "Books" then
48    product_url = calculateURLCustom(Earl, _
49      "{E5E70DED-F3D6-4277-ADAB-09D010B8355F}",null,
       null,l_dsProducts("product_id") )
50   elseif l_dsProducts("product_group_name") = "Articles" then
51      product_url = calculateURLCustom(Earl, _
52      "{6373D70E-EF0B-4A84-B8A7-032353E262E2}",null,
       null,l_dsProducts("product_id") )
53   end if

The ugly-looking bit of code on lines 43–53 actually performs a very simple and familiar task. To determine the State of a page—all roads lead to State—we need the navigation_id and tab_navigation_id. The calculateURLCustom function takes care of adding the proper n and t arguments to the query string set in Earl. The hard-coded GUID is the proper one for each given product group. We must always cater to the State or we'll get lost. If you've learned nothing else about InformIT, at least take that away with you.

54   if l_dsProducts("element_id") <> "" then
55     delete_url = _
56      calculateURL("myinformit/addto/index.asp?
       command=delete&product_id=" &
       l_dsProducts("product_id") & "&element_id=" &
       l_dsProducts("element_id"))
57   else
58     delete_url = _
       calculateURL("myinformit/addto/index.asp?
       command=delete&product_id=" &
       l_dsProducts("product_id"))
59   end if
60   delete_url = "javaScript:popDel('" & delete_url & "')"
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.