Echo $sql in your first statement and see what values are being submitted. See if any are null or not being converted to strings that is unrecognizable.
rproffitt commented: Thanks for sharing. Usually helps others when we reveal what it was. +14
diafol commented: Glad it helped :) +15
rproffitt commented: I read you wanted to loop. Missed that you wanted 3 per row. +12
egsonas commented: Hmmm.... Starnge. have you any changes to code or just putted codes in separate files? +1