when you close the query? Wouldn't it make more sense to do so when it opens?

Either way, a simple loop and $comchan oughta do the trick.