I don’t know what your database structure is so I can’t be of help on that.
Maybe these posts will help you get it figured out