473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

2D array in tag cloud

Hi,
I've tried with this since 5pm. It's now 2am and still not working. I am trying to display some tags in a tagcloud. Originally it was working with a one dimension array but I needed the id for the hyperlink so I change to a 2 dimension array. The problem is that only the last item in the array is rendered. For Some reason my array is not preserved.

Here is my code...seriously I really tried with this. Kindly assist.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3.  
  4. Function tagCloud()
  5.  
  6. Dim aDigits, tempTagHolder, biggestNum
  7. Dim aDynamic
  8.  
  9. ReDim aDynamic(1,0)
  10.  
  11.  Set conn = server.createobject("adodb.connection")
  12.  
  13.  Set objRs = server.CreateObject("adodb.recordset")
  14.  
  15.  conn.open strConn
  16.  
  17.  sql = "execute GetTagCloud"
  18.  
  19.  set objRs = conn.Execute(sql)
  20.  
  21.     While Not objRs.EOF
  22.         count = objRs("tag_count")
  23.         objRs.MoveNext
  24.     Wend    
  25.  
  26.     'Get next table with tags
  27.     Set objRs = objRs.NextRecordset()
  28.  
  29.  
  30.     While Not objRs.EOF
  31.  
  32.  
  33.     For i = 0 to count
  34.  
  35.         ReDim Preserve aDynamic(1,i) <-----------------------------Here
  36.         aDynamic(0,i) = objRs.Fields.Item("tag_id").value
  37.         aDynamic(1,i) = objRs.Fields.Item("tag_Name").value
  38.  
  39.     Next 
  40.  
  41.     objRs.MoveNext
  42.  
  43.     Wend
  44.  
  45.     objRs.Close()
  46.  
  47.     'For b = 0 to Count
  48.         'response.write(aDynamic(1,b))
  49.     'Next 
  50.  
  51.  
  52.     Call DualSorter(aDynamic,1)
  53.  
  54.  
  55.     'Get the highest tag
  56.     biggestNum = 0
  57.     lastTag =  aDynamic(1,0)
  58.     For i=0 to count
  59.         If lastTag = aDynamic(1,i) Then 
  60.             tagCount = tagCount+1
  61.         Else
  62.             If tagCount >= biggestNum Then 
  63.                 biggestNum = tagCount
  64.             End If
  65.             tagCount = 1
  66.         End If
  67.         lastTag = aDynamic(1,i) 
  68.         If i = count Then 
  69.             If tagCount >= biggestNum Then 
  70.                 biggestNum = tagCount
  71.             End If
  72.         End If
  73.     Next 
  74.  
  75.     'Output Tags
  76.     Dim lastTag, tagCount, i, newTag, loopHolder, tempNewTag, sHTML
  77.     lastTag = aDynamic(1,0)
  78.     tagCount=0
  79.  
  80.     sHTML = "<div>"
  81.  
  82.     For i=0 to count 
  83.         If lastTag = aDynamic(1,i) Then 
  84.             tagCount = tagCount+1
  85.         Else
  86.             sHTML = sHTML  & "<a href=""?tag="&lastTag&""">"&renderTag(lastTag,tagCount,biggestNum)&"</a>" 
  87.             tagCount = 1
  88.         End If
  89.         lastTag = aDynamic(1,i) 
  90.         If i = count Then 
  91.             sHTML = sHTML  & "<a href=""?tag="&lastTag&""">"&renderTag(lastTag,tagCount,biggestNum)&"</a>" 
  92.         End If
  93.     Next 
  94.  
  95.     Response.Write(sHTML&"</div>")
  96.  
  97. End Function
  98.  
  99. Function renderTag(tagName,tagCount,biggestNum)
  100.  
  101.        ...Just applying size style
  102.  
  103. End Function
  104.  
  105.  
  106. Sub DualSorter( byRef arrArray, DimensionToSort )
  107.     Dim row, j, StartingKeyValue, StartingOtherValue, _
  108.         NewStartingKey, NewStartingOther, _
  109.         swap_pos, OtherDimension
  110.     Const column = 1
  111.  
  112.     ' Ensure that the user has picked a valid DimensionToSort
  113.     If DimensionToSort = 1 then
  114.         OtherDimension = 0
  115.     ElseIf DimensionToSort = 0 then
  116.         OtherDimension = 1
  117.     Else
  118.         'Shoot, invalid value of DimensionToSort
  119.         Response.Write "Invalid dimension for DimensionToSort: " & _
  120.                        "must be value of 1 or 0."
  121.         Response.End
  122.     End If
  123.  
  124.     For row = 0 To UBound( arrArray, column ) - 1
  125.     'Start outer loop.
  126.  
  127.         'Take a snapshot of the first element
  128.         'in the array because if there is a 
  129.         'smaller value elsewhere in the array 
  130.         'we'll need to do a swap.
  131.         StartingKeyValue = arrArray ( row, DimensionToSort )
  132.         StartingOtherValue = arrArray ( row, OtherDimension )
  133.  
  134.         ' Default the Starting values to the First Record
  135.         NewStartingKey = arrArray ( row, DimensionToSort )
  136.         NewStartingOther = arrArray ( row, OtherDimension )
  137.  
  138.         swap_pos = row
  139.  
  140.         For j = row + 1 to UBound( arrArray, column )
  141.         'Start inner loop.
  142.             If arrArray ( j, DimensionToSort ) < NewStartingKey Then
  143.             'This is now the lowest number - 
  144.             'remember it's position.
  145.                 swap_pos = j
  146.                 NewStartingKey = arrArray ( j, DimensionToSort )
  147.                 NewStartingOther = arrArray ( j, OtherDimension )
  148.             End If
  149.         Next
  150.  
  151.         If swap_pos <> row Then
  152.         'If we get here then we are about to do a swap
  153.         'within the array.
  154.             arrArray ( swap_pos, DimensionToSort ) = StartingKeyValue
  155.             arrArray ( swap_pos, OtherDimension ) = StartingOtherValue
  156.  
  157.             arrArray ( row, DimensionToSort ) = NewStartingKey
  158.             arrArray ( row, OtherDimension ) = NewStartingOther
  159.  
  160.         End If    
  161.     Next
  162. End Sub
  163.  
  164.  
  165. %>
  166.  
Aug 9 '07 #1
4 2098
jhardman
3,406 Expert 2GB
I didn't look into it really deep, but your 2D array only has two possible values in one dimension. Why don't you just use 2 different 1D arrays? Just a thought.

Jared
Aug 9 '07 #2
I didn't look into it really deep, but your 2D array only has two possible values in one dimension. Why don't you just use 2 different 1D arrays? Just a thought.

Jared
Can you please explain? If I use 2 separate arrays how can I get them to sort on the same matching order?
Aug 13 '07 #3
jhardman
3,406 Expert 2GB
Can you please explain? If I use 2 separate arrays how can I get them to sort on the same matching order?
This is really easy. Say you have a list of people's names and a second list of genders. so the first list names(9) contains these:
Expand|Select|Wrap|Line Numbers
  1. gina
  2. gordon
  3. alexander
  4. peter
  5. debora
  6. misty
  7. conan
  8. subashini
  9. ali
  10. germain
and the other list genders(9) looks like this:
Expand|Select|Wrap|Line Numbers
  1. fem
  2. mas
  3. mas
  4. mas
  5. fem
  6. fem
  7. mas
  8. fem
  9. mas
  10. mas
then you can sort them like this:
Expand|Select|Wrap|Line Numbers
  1. dim i, j, tempName, tempGend
  2.  
  3. for i = 8 to 0 step -1
  4.    for j = 0 to i
  5.       tempName = names(j+1)
  6.       tempGend = genders(j+1)
  7.       if names(j)>tempName then
  8.          names(j+1) = names(j)
  9.          names(j) = tempName
  10.          genders(j+1) = genders(j)
  11.          genders(j) = tempGend
  12.       end if
  13.    next
  14. next
  15.  
  16. for each i in names
  17.    response.write names(i) & ": " & genders(i) & "<br>" & vbNewLine
  18. next
notice, I sort both arrays according to the name, I never look at the value of the second array, except that I move it to match the other array which I sorted. In the end the newly arranged array has the right gender with the right name. Let me know if this helps.

Jared
Aug 13 '07 #4
This is really easy. Say you have a list of people's names and a second list of genders. so the first list names(9) contains these:
Expand|Select|Wrap|Line Numbers
  1. gina
  2. gordon
  3. alexander
  4. peter
  5. debora
  6. misty
  7. conan
  8. subashini
  9. ali
  10. germain
and the other list genders(9) looks like this:
Expand|Select|Wrap|Line Numbers
  1. fem
  2. mas
  3. mas
  4. mas
  5. fem
  6. fem
  7. mas
  8. fem
  9. mas
  10. mas
then you can sort them like this:
Expand|Select|Wrap|Line Numbers
  1. dim i, j, tempName, tempGend
  2.  
  3. for i = 8 to 0 step -1
  4.    for j = 0 to i
  5.       tempName = names(j+1)
  6.       tempGend = genders(j+1)
  7.       if names(j)>tempName then
  8.          names(j+1) = names(j)
  9.          names(j) = tempName
  10.          genders(j+1) = genders(j)
  11.          genders(j) = tempGend
  12.       end if
  13.    next
  14. next
  15.  
  16. for each i in names
  17.    response.write names(i) & ": " & genders(i) & "<br>" & vbNewLine
  18. next
notice, I sort both arrays according to the name, I never look at the value of the second array, except that I move it to match the other array which I sorted. In the end the newly arranged array has the right gender with the right name. Let me know if this helps.

Jared
Ah ha...This looks interesting. Let me try this.
Aug 14 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: lkrubner | last post by:
I apologize for being a bit dense, but I'm trying to wrap my head around the sentence "Its purpose is to allow processes to register with a cloud to be notified of updates to the channel,...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
4
by: kevincw01 | last post by:
Anyone have a clever way to retrieve for example, items 0-29 from an array of size N>29, in random order? The catch is that I dont want to print any items more than once and I dont want to miss...
0
by: yawnmoth | last post by:
According to <http://www.rssboard.org/rss- specification#ltcloudgtSubelementOfLtchannelgt>, " specifies a web service that supports the rssCloud interface which can be implemented in HTTP-POST,...
14
by: Aaron Watters | last post by:
So, in between skiing runs I noticed a Business Week cover story on "cloud computing". The article had lots of interesting information in it like about how somebody's mom used to be an airline...
1
by: Bill Fuller | last post by:
Is anyone familier with Amazon's Elastic compute cloud for hosting applications? It appears to be UNIX based. I am wondering if anyone is familier with something similar for utility computing for...
4
by: shapper | last post by:
Hello, What is the correct markup and CSS styles to create a Tag Cloud? Should I place each tag inside a list item of an ordered list and style the list item with a different CSS class...
0
by: knorth | last post by:
The DataServices World conference offers a program for those interested in technology for data integration and data access, with emphasis on service-oriented architecture (SOA), web-oriented...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.