• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need HELP on Loops!  RSS feed

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have retriece a set of record from Database and place into the Array
DivisionID DepartmentID Class ID departmentName ClassName
123 D-1 C-1 DN-1 CN-1
123 D-1 C-2 DN-1 CN-2
123 D-2 C-1 DN-1 CN-1
123 D-3 C-3 DN-1 CN-3
345 D-4 C-4 DN-2 CN-4
So the report display as group by
Sample:
DivisionID: 123
DepartmentID: D-1
DepartmentName: DN-1
ClassID: C-1
ClassName: CN-1
ClassId: C-2
ClassName: CN-2
DepartmentID: D-2
DepartmentName: DN-1
ClassID: C-1
ClassName: CN-1
DepartmentID: D-3
DepartmentName: DN-1
ClassID: C-3
ClassName: CN-3
Division: 345
DepartmentID: D-4
DepartmentName: DN-2
ClassID: C-4
ClassName: CN-3




I got stuck at how do I print Department ID if it change within the Division ID, and how to print the Class ID group if it change within division and department id.

Many thanks for your greatful help. Thank in advance for your kindness response or hints or code hints
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This kind of thing is a matter of comparing the current value to the prior value. If they don't match you want to print the current value.

Next if a higher level in the hierarchy changes you need to force all the lower levels to print. One way to do that is to alter all the lower level "prior" values to something that can't occur in the data.


That gets a little ugly with repetition. So another way is to make nested loops. PJ Plauger called this structuring the program to match the output:

See if those ideas help!
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for a helpful hints, let me try out
Regards,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!