473,800 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

export data to csv format

52 New Member
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 3965
mwasif
802 Recognized Expert Contributor
Checkout this small post.
Dec 5 '07 #2
farukcse
52 New Member
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.c sv";

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

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

$result = mysql_query("SE LECT * FROM vehicle_info");
while($rs = mysql_fetch_arr ay($result))
{
echo $rs["user_name"].",";
echo $rs["entry_date "].",";
echo $rs["id_no"].",";
echo $rs["license_ty pe"].",";
echo $rs["vehicle_ty pe"].",";
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 Recognized Expert Top Contributor
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
farukcse
52 New Member
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
farukcse
52 New Member
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 Recognized Expert Top Contributor
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
farukcse
52 New Member
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 Recognized Expert Top Contributor
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
1865
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 file or what type? There are many selections when you choose file type. When do you need to export data? How often? Do you use DTS rather than export wizard?
2
11521
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 "yyyymmdd" without delimiter. MODIFIED BY DATESISO option has a delimiter.
16
11883
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. I can do this individually for each graph but this does not help me as I need both on the same JPEG. I thought I would try an export the form that contains both but I am having trouble. (My VBA is self taught and a little knowledge is...
10
14740
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 vba is a little confusing for me since i have never used it plus i have lost touch with vb coding since last 8 monhts. anywayz, my problem is i'm trying to export a table that's modified by me which is taken from a file at a prompt, now i have to...
1
2165
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 allowed to re-import their archived data. This all works fine, until we have to update the application for international users. The original csv files sent to users contain dates and numbers in US format. However, once imported, the numbers appear...
5
8674
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 it requires Microsoft Excel installed on every machine with my program. It is not quite convenient to do so. Is there another way to export data to Excel, or how simply create file of Microsoft Excel format from my program (of cause, the format of...
0
1974
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: ------------------------------------------------------------------------ This is how I export reports to PDF files: Dim diskOpts As New DiskFileDestinationOptions ' load report m_Report.Load(strReport)
1
1884
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 as so that the data is exported as dd/mm/yy. Every time i run this it exports the dates as dd/mm/yy nn:hh:ss i really don't understand why.
4
4914
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 which file format would be the most efficient format to import export relational data. So far we came up with two options: XML and Access MDB files and we prefer MDB files.
17
19914
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 Specifications and on some queries data is showing up in what looks like HEX. Below is an example: SQL Statement for Invoice_Header Query: SELECT !! AS inv_id, !! AS tran_date, Sum(Item_Lot_Query.total_gross) AS total_gross FROM Item_Lot_Query; The SQL...
0
10509
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...
1
10256
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
9095
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...
1
7584
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
6824
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
5477
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
5612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4152
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
3
2953
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.