473,721 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving two mysql tables as csv files

The following code only generates the first csv file. The second
request is just ignored. What am I doing wrong? I am using Mozilla
Firefox, Windows XP, and Xampp.

<?php

require 'bm_connect.php ';

// export to csv file the table bmbookmark and call it bookmarks.csv
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=bookma rks.csv");
$query = "SELECT * FROM bmbookmark";
$result = mysql_query($qu ery);
while($row = mysql_fetch_row ($result)){
print implode(",", $row)."\n";
};
mysql_free_resu lt($result);
exit();

// export to csv file the table bmcat and call it categories.csv
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=catego ries.csv");
$query = "SELECT * FROM bmcat";
$result = mysql_query($qu ery);
while($row = mysql_fetch_row ($result)){
print implode(",", $row)."\n";
};
mysql_free_resu lt($result);
exit();

?>

Regards,
Jan Nordgreen
Jul 17 '05 #1
4 2397
While the city slept, Jan Nordgreen <ro*******@hotm ail.com> feverishly
typed:
The following code only generates the first csv file. The second
request is just ignored. What am I doing wrong? I am using Mozilla
Firefox, Windows XP, and Xampp.

<?php

require 'bm_connect.php ';

// export to csv file the table bmbookmark and call it bookmarks.csv
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=bookma rks.csv");
$query = "SELECT * FROM bmbookmark";
$result = mysql_query($qu ery);
while($row = mysql_fetch_row ($result)){
print implode(",", $row)."\n";
};
mysql_free_resu lt($result);
exit();

[...]

Do you really want the script to exit here? Or would you prefer it to carry
on and do the second csv file? ;-) If so, take out this first instance of
exit();

Cheers,
Nige

--
Nigel Moss.

Email address is not valid. ni***@nigenetDO G.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #2
So that is what exit(); does! :)

When I removed the exit(); only one csv file was created.

First the first table was listed,

then this message was listed in the csv file:

<b>Warning</b>: Cannot modify header information - headers already
sent by (output started at C:\jans data\jan programs\apache php mysql
etc\xampp\htdoc s\xampp\excel.p hp:31) in <b>C:\jans data\jan
programs\apache php mysql etc\xampp\htdoc s\xampp\excel.p hp</b> on line
<b>37</b><br />

and another warning:

<b>Warning</b>: Cannot modify header information - headers already
sent by (output started at C:\jans data\jan programs\apache php mysql
etc\xampp\htdoc s\xampp\excel.p hp:31) in <b>C:\jans data\jan
programs\apache php mysql etc\xampp\htdoc s\xampp\excel.p hp</b> on line
<b>38</b><br />

then the second table was listed,

then the html code of the main php file was listed.

I wanted two csvs, not one. I don't like error messages in the csv
files. I don't like the html code listed in the csv file.

What am I doing wrong?

Regards,
Jan Nordgreen
Jul 17 '05 #3

"Jan Nordgreen" <ro*******@hotm ail.com> wrote in message
news:34******** *************** ***@posting.goo gle.com...
So that is what exit(); does! :)

When I removed the exit(); only one csv file was created.

First the first table was listed,

then this message was listed in the csv file:

<b>Warning</b>: Cannot modify header information - headers already
sent by (output started at C:\jans data\jan programs\apache php mysql
etc\xampp\htdoc s\xampp\excel.p hp:31) in <b>C:\jans data\jan
programs\apache php mysql etc\xampp\htdoc s\xampp\excel.p hp</b> on line
<b>37</b><br />

and another warning:

<b>Warning</b>: Cannot modify header information - headers already
sent by (output started at C:\jans data\jan programs\apache php mysql
etc\xampp\htdoc s\xampp\excel.p hp:31) in <b>C:\jans data\jan
programs\apache php mysql etc\xampp\htdoc s\xampp\excel.p hp</b> on line
<b>38</b><br />

then the second table was listed,

then the html code of the main php file was listed.

I wanted two csvs, not one. I don't like error messages in the csv
files. I don't like the html code listed in the csv file.

What am I doing wrong?

Regards,
Jan Nordgreen


You're trying to download two documents to the user - that's what's wrong.
You can't. Aa a suggestion, use Javascript to open a window for each
download (even if that will be ugly).

Garp
Jul 17 '05 #4
While the city slept, Jan Nordgreen <ro*******@hotm ail.com> feverishly
typed:
So that is what exit(); does! :)
It does exactly what it says on the tin! ;-)
When I removed the exit(); only one csv file was created.


Sorry. I didn't read your code properly. I can see what it is doing now.

As an alternative, you *could* produce a script to write the data from the
tables into two csv files on the server (see
http://www.php.net/manual/en/ref.filesystem.php for some info on PHP's file
handling functions), then make a link to each file on the page, or even then
open a page that presents each of the two files in <spit>frames</spit>...
just some thoughts.

Hope that helps,
Nige

--
Nigel Moss.

Email address is not valid. ni***@nigenetDO G.org.uk. Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3525
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
0
3943
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
6
22529
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all run 32gig 15k rpm raid 5 on u320 perc raid cards, dell 2600/4600's with single channel backplanes (new ones will have dual channel) All have 2 gig of ram, but I've never seen mysql use more than 300mb of ram.
2
1701
by: mike vidal | last post by:
Is it possible to restore a mysql server if all that you have is the data files. This database uses innodb tables.
1
3361
by: Richard Huxton | last post by:
On Thursday 12 February 2004 20:25, Prashanthi Muthyala wrote: > Hi Richard Hi Prashanthi - nice to hear from you again. I've taken the liberty of cc-ing the general list on this, since there may be others who can help here. > I am trying to migrate the database and its tables from mysql in my > windows machine to postgresql in my new red hat linux . I was following > your links which has converstions from msaccess,mysql to postgresql...
1
3379
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer uses his own php shopping cart to receive customer orders. The configuration was done via cPanel with no external modifications - which produced no protests when built, ran and connected with no
3
5765
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard drive onto a USB External Hard Drive. I have to assume I also copied the data. I
1
2828
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work. Despite entering the required lines to "my.ini" (the new my.cnf) through notepad AND MySQL Administrator, the cache does not work. So, today I took a peek at the 'Health' tab in MySQL Administrator.
110
10605
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
0
9367
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
9131
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
9064
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...
0
8007
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
6669
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
5981
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
4484
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...
1
3189
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
2130
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.