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

export data to csv format

Dear Sir,
Can anyone tell me how to export data from MySQL database to a csv file using php code i.e without using phpmyadmin?

Regards,
Fauk Chowdhury.
Dec 5 '07 #1
8 3944
mwasif
802 Expert 512MB
Checkout this small post.
Dec 5 '07 #2
Checkout this small post.
Dear Sir,
Thanx for your reply.i modified your code according to my requirement but i am facing a problem with characters set i.e there are some data at database like as plate_no : 1 2 3 ص ص ص but when i exported it in csv format i see it as 1 2 2 3 س س س. so can you tell me where is my problem or how can i solve it.
[php code]
<?php
header('Content-Type: text/html; charset=utf-8');
// Connect to database
mysql_connect("localhost", "root", "root123");
mysql_select_db("medgulf");

// mention the file name to display in download prompt
$file_name = "download.csv";

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");

// Output header
//echo "Name,Code"."\n";

$result = mysql_query("SELECT * FROM vehicle_info");
while($rs = mysql_fetch_array($result))
{
echo $rs["user_name"].",";
echo $rs["entry_date"].",";
echo $rs["id_no"].",";
echo $rs["license_type"].",";
echo $rs["vehicle_type"].",";
echo $rs["plate_no"].",";
echo $rs["chassis_no"].",";
echo $rs["body_type"].",";
echo $rs["model_year"].",";
echo $rs["status"]."\n";
}
?>
Dec 6 '07 #3
code green
1,726 Expert 1GB
Are you viewing the csv in a spreadsheet program or in a plain text program?
i think this is the culprit rather than your code.
Dec 7 '07 #4
Dear Sir,

i am veiwing this in spreadsheet . is spreadsheet making problem ? how to solve this? please reply .

Thanks inadvance,

faruk chowdhury
Dec 7 '07 #5
Dear Sir,

i am veiwing this in spreadsheet . is spreadsheet making problem ? how to solve this? if i want ot make a text file what i have to do? please reply .

Thanks inadvance,

faruk chowdhury
Dec 7 '07 #6
code green
1,726 Expert 1GB
I am not sure of how much control can be weilded to force another application on how to interpret a character set.
Assuming you are using Excel, Excel is actually converting the characters.
Do they look OK in notepad.
If so the data is fine, it is Excel causing the problem
Dec 7 '07 #7
Dear Sir,
Excel is causing the problem.if i save it in .txt format then there is no problem. but i need to save it in excel fomat . so can you tell how can i do it?

Regards,
Fauk Chowdhury.
Dec 8 '07 #8
code green
1,726 Expert 1GB
Excel is causing the problem.if i save it in .txt format then there is no problem. but i need to save it in excel fomat
No, you need to OPEN it in Excel format, you are saving it in CSV format.
Excel is interpretating your character set wrongly when you open the csv file.
Notepad isn't which proves your data IS NOT being corrupted.
I don't know how to tell Excel to transalate any character set a certain way.
Not even sure you can.
Sorry, all I can suggest is studying the subject of character encoding.
I don't know much about it.
Dec 10 '07 #9

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

Similar topics

1
by: Do Park via SQLMonster.com | last post by:
Hello all, I don?t often export data from a table. I am wondering how you export data from a table. I?d like to know how you export in real world. Do you export data from a table to a flat...
2
by: hikums | last post by:
Hello, If I export a file containing date field, export to "/james/j.txt" of DEL select a1,adate from a The date is represented in YYYY/MM/DD format as expected. Output I need is to be in...
16
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
10
by: Neil | last post by:
Hi guyz, just trying out this google feature so if i post if in the wrong area i appologize. now to my question. BTW i'm new to access programming, i've done a little vb6.0 and vb.net but access...
1
by: cab2 | last post by:
We currently have an application built in Access that takes in a csv file using docmd.transfertext. We allow users to export their data to a file for later use (csv format). Users are also...
5
by: Igor | last post by:
Hi everyone! I have a question about exporting data to Microsoft Excel. I am writing program in C# and have to export some data to excel workbook. It works very good using OLE technology, but...
0
by: David Valle | last post by:
Hi, i've follow an example that Gabriele G. Ponti wrote on 8/5/2003 about the export of a report made in Crystal Report in PDF format, this: ...
1
by: Gilz | last post by:
Hi I am having trouble with the transfertext acexportdelim function. I have written several routines that export queries with date fields. I have put format statements in the download queries...
4
by: Max2006 | last post by:
Hi, We are developing a SQL server based asp.net application. As part of requirement we should allow users import/export some relational data through web user interface. We are investigation...
17
by: chadh | last post by:
Hello, I'm having some troubles exporting a query to a csv file. I am able to use the doCMD.TransferText to output the query to the csv file, however, I cannot get it to use the Export...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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,...

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.