First, the IF statement has an open paren but not a closing paren. Check on this.
Second, assign the $res['CatID'] to a single variable before using it in the print command.
Third, add a border to the table command if you can't see the table itself.
Fourth, indent your code in blocks to make it easier to read and debug. For example, after an IF, or after a WHILE, or after a FOR.
Best of luck!
Phil.