refactor mysql pref table to use a loop and look lots better.