Group array and give each distinct element a total

Results 1 to 2 of 2

Thread: Group array and give each distinct element a total

  1. #1
    Join Date
    Dec 1969

    Default Group array and give each distinct element a total

    I have an array and the output is displayed like this:<BR><BR>Steve<BR>Amos<BR>Brian<BR>Steve<BR>Jo hn<BR>Brian<BR><BR>I actually want my array to be displayed like this:<BR><BR>Steve (2)<BR>Amos (1)<BR>Brian (2)<BR>John (1)<BR><BR>Here is my code:<BR><BR>&#060;u&#062;Group1:&#060;/u&#062;<BR><BR>&#060;%for i=1 to Var1%&#062;<BR>&#060;%=Var1P(i)%&#062;<BR><BR>&#06 0;%next%&#062;<BR>&#060;p&#062;<BR><BR><BR>Can anyone please help me .....

  2. #2
    Join Date
    Dec 1969

    Default How did you create array?

    If it came from a DB query, then change the DB query to add an ORDER BY (and maybe a GROUP BY?) and it becomes much easier.<BR><BR>For example:<BR><BR> SELECT name, Count(name) AS nameCount FROM table GROUP BY name<BR><BR>That will do it for you, even getting the appropriate counts as the second field of the RecordSet.<BR><BR>********************<BR><BR>If this array comes from some other source, then the easiest way would be to first *sort* the array (see the ASPFAQs for various ways of doing that) and *then* consolidate, since now the elements with the same values will be adjacent.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts