473,659 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a word doc using php?

127 New Member
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 2037
JKing
1,206 Recognized Expert Top Contributor
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
Antonio Marcos
2 New Member
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 New Member
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,maili d, 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(candidated etails.php)... from this page (candidatedetai ls.php) i want to create a word doc that contains all the info about 'yyyy'.

i am passing cid from candidatedetail s.php to createdoc.php.. .


thank you!
Jan 12 '11 #4
code green
1,726 Recognized Expert Top Contributor
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
1592
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 support. You can check it out at www.xpertdoc.com. From: Rudy Ko (rko@lucent.com) Subject: Create word document View: Complete Thread (4 articles)
1
3399
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 img content type) for its output. In other words: App A.ASP contains the code: <%Response.ContentType = "application/vnd-msword"%> <img src="B.ASP">
3
2235
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
4671
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 document. Thanks for your precious help
1
1006
by: hullyi | last post by:
how can I generate a Word document on the fly with c# tools only or by javascrip
0
1193
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 this point, but what happens is the tables get nested within each other, I want it like the following: Table 1 <CRLF> Table 2
0
1213
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 support. You can check it out at www.xpertdoc.com. Message 1 in thread From: Jeff Kennedy (jkennedy@hotboxhosting.com)
0
289
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 document. Thanks for your precious help
2
2306
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 the sql server data first.Then add the xml template in the ms word add-in option. Is it possible? Can anyone point me to the right direction? Thanks
0
1430
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 using vb please let me know sajil
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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
8523
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
8626
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...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.