it looks like it's doing what you told it to. try instead of setting fieldname="d" to just have it print out the actual field name. i'm thinking perhaps it's only running that little nested loop on fields of certain types or which do not have null values in the sql results. on the other hand, you only posted partial code plus no idea what the table looks like. hehe