think about writing a generic function using hashes and join to write your SQL and do your SELECTs
and finally... you had the right idea in the first place. You should be able to fetch the row even if there isn't anything in it - then, once you've got it, you can print something sensible if it's empty. Have a fiddle about with it, post the code how it was when it was kikkin' up them errors (grin) - maybe they weren't caused by the database? Or for a different reason?
Anyway, hope these vague ramblings have been some help,