473,404 Members | 2,114 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,404 software developers and data experts.

Converting Mysql data to Excel

Dear All,

I am trying to download the data from mysql to excel (CSV). I get a quote but when i download the data, its fetching the only data but I want to put the column name also.

Expand|Select|Wrap|Line Numbers
  1.  <?php
  2. include_once("db_connect.inc.php");
  3.  
  4. $query  = "SELECT * FROM logintable";
  5. $result = mysql_query($query) or die('Error, query failed');
  6.  
  7. $tsv  = array();
  8. $html = array();
  9. while($row = mysql_fetch_array($result, MYSQL_NUM))
  10. {
  11.    $tsv[]  = implode("\t", $row);
  12.    $html[] = "<tr><td>" .implode("</td><td>", $row) .              "</td></tr>";
  13. }
  14.  
  15. $tsv = implode("\r\n", $tsv);
  16. $html = "<table>" . implode("\r\n", $html) . "</table>";
  17.  
  18. $fileName = 'logintable.xls';
  19. header("Content-type: application/vnd.ms-excel");
  20. header("Content-Disposition: attachment; filename=$fileName");
  21.  
  22. echo $tsv;
  23. //echo $html;
  24.  
  25. ?>
Please help me in putting the column name. in the excel file.

Thanks in advance

Regards,
Robin.
Feb 12 '10 #1
2 2075
Markus
6,050 Expert 4TB
Can you clarify the question please: you need to get the MySQL column titles also?

http://www.php.net/manual/en/functio...ist-fields.php
Feb 12 '10 #2
Hi..
sure, I want to to download the data from mysql to excel. I am able to download with the above code but the problem is that when I download the data into excel the column name of the table is not download. It download the only the data. Eg. table1 contain c1, c2 column
C1 C2
abc india
xyz india

with the above code, i can download abc, india but not the column name C1 and C2 not in the excel.

Kindly help in downloading column name also.


With Regards,

Robin
Feb 13 '10 #3

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

Similar topics

0
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ...
3
by: bawar | last post by:
Hey, I can say I belong to the newbies in this subject. I own my own website with mySQL-databases, but now I have to show one table of those mySQL-databases in an excel worksheet. It is the...
4
by: Piotr | last post by:
Hi I have many files in Excel and I need to transfer them into MySQL, is tehere any free and easy solution ?
2
by: John | last post by:
I'd love to hear some expert opinion on my situation. My department relies on Excel as a database, which causes crashing due to resource depleting and basically is just too slow. For example, a...
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I am converting Excel data into a Dataset in C#. There are around 24 columns in the Excel Sheet. First I tried to insert one row with correct values in the Excel sheet. i.e. for text columns...
6
by: Piotr | last post by:
Hi, I have following problem: I use a form in excel to send data into mysql server, everything is ok unless I have to deal with decimals or data fields, this simple are not recognized. For...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
8
by: Michael B. Trausch | last post by:
I was wondering if anyone has had any experience with this. Someone I know is trying to move away from Microsoft Works, and I am trying to look into a solution that would convert their data in a...
5
by: Sport Girl | last post by:
Hi everybody. I am new in PERL language and working in it since little hours, actually i am still a trainee and i need help please. In fact, i need a script in PERL that enables me to retrieve...
1
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...
0
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...

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.