in reply to problem with returning all records
Your code doesn't display this anywhere, you've not shown where you define $html or print it. You're clobbering (not appending to) $html so if you print it outside of the foreach loop it will only have one result.
In Section
Seekers of Perl Wisdom