i'm a bit confused..
you want to create a zip file based on the filename you get from the database?
or do you want to extract the zip file into your filesystem?
if you want to do my first question, then you'll be better off reading how to use either tar or gzip on your system. Find out how to append to a zip file, once you know how to do that, everything else should be quite easy.
to help you bit, this is what i'm thinking you might have to do.
sql query and get info.
if zip does not exist in filesystem then
create zip and add file to zip
if zip does exist then
add file to zip
continue until query is done.
i hope that helps you in something.