It seems like the line:
Code:
local name, _, standingID, _, _, _, _, _, isHeader, _, _, isWatched, _, factionID = GetFactionInfoByID(id)
should be:
Code:
local name, _, standingID, _, _, _, _, _, isHeader, _, _, isWatched, _, factionID = GetFactionInfo(i)
otherwise you are iterating from 1 to GetNumFactions() but checking the same id over and over which doesn't change in the loop so you could just do it once.