MS Word Template for PHP/MySQL

Could anybody do a small sample regular Word document with anchors (is that what they are called?) so that I could propogate those with MySQL entries? IE:

Hello {firstname}{lastname},

Thanks for your interest in our product.

Where {firstname}{lastname} would be values from a row of MySQL and the columns firstname, lastname.
drakkarnoirAsked:
Who is Participating?
 
venkateshwarrConnect With a Mentor Commented:
I did not get your question.

If you want to create a word document... the following links have snippets that can help you.

http://www.programmershelp.co.uk/phpcreateword.php
http://www.phpbuilder.com/columns/yunus20031124.php3?page=2
0
 
madwaxConnect With a Mentor Commented:
<?php
$word = new COM("word.application") or die ("couldnt create an instance of word");
$word->visible = 1;
$word->Documents->Add();

//replace with your connection to database here...


$sql = "SELECT firstname,lastname FROM myTable WHERE id=X";
$result = mysql_query($sql);
$row = mysql_fetch_object($result);

$word->Selection->TypeText("Hello".$row->firstname." ".$row->lastname."\n\n Thanks for your interest in our product.");
$word->Documents[1]->SaveAs("sampleword.doc");
$word->Quit();
$word->Release();
$word = null;
?>
0
 
jkna_gunnCommented:
he means autotext, and i will try and give you a solutions by monday.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
drakkarnoirAuthor Commented:
Still here jkna_gunn?
0
 
jkna_gunnCommented:
yeah sorry, was a holiday here. ive not had a chance to look into it yet.
do you know how to create these "anchors" in word as ive not used that before.
0
 
drakkarnoirAuthor Commented:
Nope, I'm not even sure if they are called anchors, I was just taking a guess with that word...
0
 
drakkarnoirAuthor Commented:
Still here jkna_gunn?
0
 
jkna_gunnCommented:
im here but i need to find out how to do these "anchors" in word first.

worst comes to worst might just have to do a search replace on the strings.
0
 
drakkarnoirAuthor Commented:
You mean bookmarks?

"To create a Bookmark in a MS Word document, click on Insert/Bookmark. You can highlight a word or sentence and make them a Bookmark."

So then using that idea, we just have to tell MS Word using COM+ to look for the bookmark, and select the range of it, and replace the value of it with our value:

<?php
$fullname = $firstname . $lastname;
$bookmarkname = "NAME";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
$range->Text = $fullname;
?>

1
 
jkna_gunnCommented:
and that doesn't work?
0
 
drakkarnoirAuthor Commented:
It does, I just thought you had a better way :)
0
 
jkna_gunnCommented:
not that i know of sorry :(
0
 
drakkarnoirAuthor Commented:
Hmmmm, in that case, I'm going to have to award venkateshwarr with the points, as he pointed me to the link which spoke about that, and give some points to madwax for his input. Thanks for your participation jkna_gunn, I really apppreciated your help with my labeling question :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.