I'm sorry to have troubled you. / Thank you for your trouble.
This phrase may be used to thank teachers for having helped you solve a problem, for having taken your child to a medical facility, or for having otherwise gone out of their way to help you in some matter.