First of all the question, about which dataset you are talking about?
- DYNAMIC ???
- NON-DYNAMIC ???
Second provide some infos about your used elements and their IDs.
Third show an ecxerpt of your database including the two TAG-Fields.
And last but not least, where is your already generated code???