As to the first: yes, I'm always getting errors because I forget the ; and it is not always the line number mentioned in the error message. But it look like you've figured that one out.
As to the second, Whoops. Looks like you've got your table generation scrambled. For some reason I can't view the source in IE, and when I tried to view it from another machine it tried to FTP the page??? What's up??
My code was just an explanation of the logic required. It does need you to think about it. Specifically, the first time into the loop you have no unit to terminate before starting the new unit header. After that, you will need to clean up and finish off the display of members details of one unit before starting the unit header for the new one. So you need to work out a counter, etc.
One piece of advise, always have a test site. When changing a working page, test the new version before replacing the old one. And SAVE the old one incase you want to back-out of the changes. Basic development practice that will stop you getting lost and save you a lot of headaches. You should end up with a series of versions, each carefully annoted with the changes included from generation to generation. Work you logic out with pencil and paper:
start table
first unit header
unit members
end unit members
next unit header
unit members
end unit members
next unit header
... etc
last unit members
end table
In this case I would have the start table and end table outside the while loop, and be using tables within the main table for headers and members. Good luck.