I'm trying to write a small script/program in PHP to emulate a Microsoft Mail Merge.
The steps I believe I need are as follows:
1. Upload data to MYSQL DB via csv file. (OK)
2. PHP page with template letter where the data will be merged to.
3. Each record must be merged/imported into the template letter and then this must be saved as a file in a directory on the server (all files will go to the same directory) - I'm not sure which is easiest/best to use: html, rtf, or PDF.
4. Each file must have the file name as specified by a field in the DB - ie the clients account no.).
EG, I have 10 customers each with their own information in the DB. I want to end up with 10 letters in the directory/server folder - as html, rtf, or pdf - with the file names being the Client's account number (taken from the DB).
I will download this directory/folder to my Mac to print or email them at a later date.
So far, I have the database set up (that was the easy bit). I have the letter done as an XHMTL document (using a mix of tables and CSS for layout & presentation) saved as a PHP file, using a php echo statement where I want the info from the DB to appear.
The rest has me befuddled, discombobulated, and generally confused.
I presume I need to write a function that goes through each row of the DB, puts it in the .PHP (template) file, then saves to the directory '/letters' until it reaches the end.
I also would prefer to save the documents as PDFs, but it doesn't seem as straightforward as I had hoped.
Does anyone know of any script that does this already, or is there something I can adapt?
I know what I want to do, I think I know the principles... I just don't know how to put it altogether!
If there's any kind soul out there who can give me a few pointers, I'd be a happy, happy bunny.
Special deal for Yahoo! users & friends - No Cost. Get a month of Blockbuster Total Access now