Gossip problem c++

Hello i want to make npc with gossip menu. Depends on your class (paladin,mage etc.) to show list with each avaiable spec and to do some staff… but have some error and menus are not working . is show random gossip icon’s and random count of options… here is my code http://pastebin.com/4LwDXiyW if some 1 can tell me where is error will be nice xD

P.S. is work on accounts without GM permissions

I sugest you to use db+conditions.