473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to create a word doc using php?

127 100+
word document should display the details about the candidate.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("config.php");
  3.  
  4. //$table = 'table_name';
  5. $outstr = NULL;
  6.  
  7. $id = $_GET['id'] ;
  8.  
  9. header("Content-Type: application/msword");
  10. header("Content-Disposition: attachment;Filename=candidate.msword");
  11.  
  12. /*$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
  13. mysql_select_db("db",$conn);*/
  14.  
  15. // Query database to get column names 
  16. $result = mysql_query(" select * from candidate where cid='$id'");
  17. // Write column names
  18. while($row = mysql_fetch_array($result)){
  19.     $outstr.= $row['cid'].',';
  20. $outstr = substr($outstr, 0, -1)."\n";
  21.  
  22. // Query database to get data
  23. $result = mysql_query("select * from candidate where cid='$id'");
  24. // Write data rows
  25. while ($row = mysql_fetch_assoc($result)) {
  26.     $outstr.= join(',', $row)."\n";
  27. }
  28.  
  29. echo $outstr;
  30.  
  31. ?>
  32.  
a blank word doc is created...

if i change this code,

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query(" select * from candidate where cid='$id'");
  2.  
as like this,
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query(" select * from candidate");
  2.  
it works fine...

but i want to display only a particular candidate's details... not all the candidate...
how to do it? plz help.

i tried in pdf, i m also having same problem in that select query...
Jan 11 '11 #1
4 2015
JKing
1,206 Expert 1GB
Use echo "Error: " . mysql_error();after your query to get a better idea of what is going wrong. Is cid numeric or string?
Jan 11 '11 #2
If I understand...
Are you get not make a efficient instruction on SQL, isn't?

Where you put the character '*', you should put the fields of the tables in your database.

Example:
If I have a table:
people(id, name, age, address);

And here a simple select:
SELECT name FROM people WHERE id = 2;

with that I'll get a name of the people where your ID equal two.

CYA!
Jan 11 '11 #3
impin
127 100+
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query(" select * from candidate where cid='12'");
  2.  
if i give like this it works. but what's the problem is,
there are several candidates in the table. i want to create each candidate's details as a word doc.

for example,
candidate table consists of several fields like cid,cname,mailid, phone,etc....
my candidate's list is like,
cid cname
14 xxxx
15 yyyy
16 bbbb
17 zzzz znd so on.

when i click the 'yyyy' it will retrieve all the info about 'yyyy' in a separate page(candidatedetails.php)... from this page (candidatedetails.php) i want to create a word doc that contains all the info about 'yyyy'.

i am passing cid from candidatedetails.php to createdoc.php...


thank you!
Jan 12 '11 #4
code green
1,726 Expert 1GB
This is exactly the same problem as your other post.
http://bytes.com/topic/php/answers/9...iles-using-php
You are ignoring advice on how to debug your problem from me and JKing,
instead preferring to repeat the same question.
We can't help you if don't help yourself!
Jan 12 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Francis Dion | last post by:
You might want to investigate XpertDoc. It creates genuine MS-Word documents without making any call to the MS-Word application, making it more reliable, much faster and easier to deploy and...
1
by: unotin | last post by:
I have an application in ASP that exports to Word using the Response.ContentType method. The application references another ASP page through the img tag that uses a Response.BinaryWrite (of an...
3
by: Sérgio Almeida | last post by:
Greetings it is possible to create Word documents using C#? If so, where can I find examples/help for this? Thank you very much Sérgio
1
by: Johann | last post by:
Hi, anyone could help me with finding info on how to create Word documents on the fly with ASP.NET ? I need, from an existing template, to generate a new file with data filled in the word...
1
by: hullyi | last post by:
how can I generate a Word document on the fly with c# tools only or by javascrip
0
by: Mills | last post by:
Hi, I am currently trying to automate word using c#, I have created a ..dot file and have placed a bookmark in the middle of the document, I am trying to create a variable number of tables from...
0
by: Francis Dion | last post by:
You might want to investigate XpertDoc. It creates genuine MS-Word documents without making any call to the MS-Word application, making it more reliable, much faster and easier to deploy and...
0
by: Johann | last post by:
Hi, anyone could help me with finding info on how to create Word documents on the fly with ASP.NET ? I need, from an existing template, to generate a new file with data filled in the word...
2
by: ads | last post by:
hi i was given a task to display sql server data in ms word using xml. Im currently doing research to accomplish the task. What i have in mind is to create an xml template (or schema?) to load...
0
by: sajil | last post by:
hai i have a problem i have done a program in visual basic 6 where i connected to word but i am not able to create a table in word if possible please tell me and can we move the table in the word...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.