Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 06:42 AM
Jan Nordgreen
Guest
 
Posts: n/a
Default 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=bookmarks.csv");
$query = "SELECT * FROM bmbookmark";
$result = mysql_query($query);
while($row = mysql_fetch_row($result)){
print implode(",", $row)."\n";
};
mysql_free_result($result);
exit();

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

?>

Regards,
Jan Nordgreen
  #2  
Old July 17th, 2005, 06:42 AM
nice.guy.nige
Guest
 
Posts: n/a
Default Re: Saving two mysql tables as csv files

While the city slept, Jan Nordgreen <room23111@hotmail.com> feverishly
typed:
[color=blue]
> 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=bookmarks.csv");
> $query = "SELECT * FROM bmbookmark";
> $result = mysql_query($query);
> while($row = mysql_fetch_row($result)){
> print implode(",", $row)."\n";
> };
> mysql_free_result($result);
> exit();[/color]
[...]

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. nigel@nigenetDOG.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!


  #3  
Old July 17th, 2005, 06:42 AM
Jan Nordgreen
Guest
 
Posts: n/a
Default Re: Saving two mysql tables as csv files

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\htdocs\xampp\excel.php:31) in <b>C:\jans data\jan
programs\apache php mysql etc\xampp\htdocs\xampp\excel.php</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\htdocs\xampp\excel.php:31) in <b>C:\jans data\jan
programs\apache php mysql etc\xampp\htdocs\xampp\excel.php</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
  #4  
Old July 17th, 2005, 06:42 AM
Garp
Guest
 
Posts: n/a
Default Re: Saving two mysql tables as csv files


"Jan Nordgreen" <room23111@hotmail.com> wrote in message
news:3488b88c.0406081358.2df37a77@posting.google.c om...[color=blue]
> 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\htdocs\xampp\excel.php:31) in <b>C:\jans data\jan
> programs\apache php mysql etc\xampp\htdocs\xampp\excel.php</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\htdocs\xampp\excel.php:31) in <b>C:\jans data\jan
> programs\apache php mysql etc\xampp\htdocs\xampp\excel.php</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[/color]

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


  #5  
Old July 17th, 2005, 06:42 AM
nice.guy.nige
Guest
 
Posts: n/a
Default Re: Saving two mysql tables as csv files

While the city slept, Jan Nordgreen <room23111@hotmail.com> feverishly
typed:
[color=blue]
> So that is what exit(); does! :)[/color]

It does exactly what it says on the tin! ;-)
[color=blue]
> When I removed the exit(); only one csv file was created.[/color]

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. nigel@nigenetDOG.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!


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles