473,770 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create an ms word file from MySQL data using PHP

Hi,

I have customer contact information in a MySQL DB. The standard stuff:
first name, last name, city, state, zip, etc.

I'd like to write a PHP script that will take a customer ID range
(e.g., customer 10000 - 11000) and stick those into an MS Word
document, plain text document, or a PDF (any of the three will work).

The key is that each record has to have a page break after it so that
each customer prints on a separate piece of paper.

Anyone know how to do this?

Thanks in advance for any suggestions, links to tutorials, etc. :)
-- Eric
Jul 17 '05 #1
4 11620
Eric Linders wrote:
I have customer contact information in a MySQL DB. The standard stuff:
first name, last name, city, state, zip, etc.

I'd like to write a PHP script that will take a customer ID range
(e.g., customer 10000 - 11000) and stick those into an MS Word
document, plain text document, or a PDF (any of the three will work).

The key is that each record has to have a page break after it so that
each customer prints on a separate piece of paper.

Anyone know how to do this?


I'd go with the plain text document:

<?php
$txt_file = fopen('textfile .txt', 'wb') or die('Cannot open.');
foreach($dbreco rd as $customer) {
$string = 'Name: ' . $customer['name'] . "\r\n";
$string .= 'Address: ' . $customer['address'] . "\r\n";
// ...
$string .= "\x0C\r\n"; ## \x0C is the "form-feed" character
if (!fwrite($txt_f ile, $string)) die("Unable to write to textfile.txt");
}
fclose($txt_fil e);
?>

But I have no idea how ms word will interpret the form-feed character.

HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

"Eric Linders" <el********@hot mail.com> wrote in message
news:49******** *************** ***@posting.goo gle.com...
Hi,

I have customer contact information in a MySQL DB. The standard stuff:
first name, last name, city, state, zip, etc.

I'd like to write a PHP script that will take a customer ID range
(e.g., customer 10000 - 11000) and stick those into an MS Word
document, plain text document, or a PDF (any of the three will work).

The key is that each record has to have a page break after it so that
each customer prints on a separate piece of paper.

Anyone know how to do this?

Thanks in advance for any suggestions, links to tutorials, etc. :)
-- Eric


Mmm, go here: http://www.programmershelp.co.uk/phpcreateword.php

HTH
Garp
Jul 17 '05 #3
Pedro Graca <he****@hotpop. com> wrote in message news:<2h******* *****@uni-berlin.de>...
Eric Linders wrote:
<SNIP>

Anyone know how to do this?


I'd go with the plain text document:

<?php
$txt_file = fopen('textfile .txt', 'wb') or die('Cannot open.');
foreach($dbreco rd as $customer) {
$string = 'Name: ' . $customer['name'] . "\r\n";
$string .= 'Address: ' . $customer['address'] . "\r\n";
// ...
$string .= "\x0C\r\n"; ## \x0C is the "form-feed" character
if (!fwrite($txt_f ile, $string)) die("Unable to write to textfile.txt");
}
fclose($txt_fil e);
?>

But I have no idea how ms word will interpret the form-feed character.

HTH

Thanks Pedro, I'll try it today! :-) I will let you know how it works out for me.

- Eric
Jul 17 '05 #4
*** Garp wrote/escribió (Thu, 20 May 2004 19:32:58 GMT):
Mmm, go here: http://www.programmershelp.co.uk/phpcreateword.php


Please note that you must be running PHP in a Windows server with MS Office
installed for this to work.

As for the PDF option, you have a number of libraries. A free one is:

http://www.fpdf.org/
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2198
by: Cleber Hostalácio de Melo | last post by:
Hi, I need to change the stop word file used by the MySQL in fulltext seach. The documentation (www.mysql.com/doc/en/Fulltext_Fine-tuning.html) explains how to inform to MySQL the new stop word file through the "ft_stopword_file" variable. But I could not find any reference to the layout of this file, for example, how to separate each stop word in the list?
2
13928
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks ( weekstart datetime not null primary key, weekend datetime not null )
1
1526
by: AmitK | last post by:
is it possible to create a myi, myd file for mysql using a C program. I am using Stata that is written in C API, and I want to write the data out to MYSQL database. Using ODBC and loading the data in MYSQL from STATA takes forever. Can anyone please tell me if I can create the myd files by using the data in memory thru C programming. thanks Amit
7
4994
by: Daniel Walzenbach | last post by:
Hello, I want to create a Word XML file based on the input users make in a VB.NET application. I imagine creating a template in Word and saving it as a XML file. I then want to fill the template (in my application) based on the user input. When the document gets opened there should be fields users can change but others should be prevented from beeing changed (I know that an "open" file format like XML can always be modified to allow...
2
13533
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a template file containing the field names Line1 thru Line5 for each record to be printed. If a...
0
3231
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want to register new customer or companies they will enter the information in Windows Form and the program automaticaly creates the WORD document under specific folder under application path. Once the empty word file created than ask user if they want...
6
8663
by: Justin | last post by:
Hi all, i need some help over here... i found the solution to export file from mysql db into *.csv. but is there anyway to convert the contents into *.doc and save in my webserver and providing a link for the end users to download the word file? FYI, the database records are obtained by end users submitting the forms themselve and i saved it in my db... Thanx.
3
1900
by: ravikiranveluguleti | last post by:
hi, this is ravikiran i am working on a project(using java & mysql) that requires creation of a editable mysql file that contains all the data present in a particular table ,(like .mdb file that MS-Access will create for every table).Is mysql having a facility to create such file.If so how??? help me thanx in advance.
0
2544
by: dbsog7777 | last post by:
I was trying to use the sample code below, but I encountered two errors: Application.DoEvents() and AutoText(entry). I am not sure how to correct the errors. I trying to use the sample code to create a mailmerge routine that accepts data from my SQL database and create a word doc that ce be previewed in the client browser. My OS is XP Pro and I am coding in VB.NET. Protected Sub CreateWordMailMerge(ByVal strLabelName As String, _ ...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.