@dakshayani : You should directly use $result.id for the option group id instead of looping.