Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 635043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:21:41+00:00 2026-05-13T20:21:41+00:00

I am trying to export data from my MySQL database to multiple CSV files

  • 0

I am trying to export data from my MySQL database to multiple CSV files and then GZIP them.

I have a couple of problems which make exporting it to a CSV file complicated …

  1. Several fields (10) need to be in 1 CSV file
  2. Other fields (multiple!) are serialized and need to be exported into a different CSV file with two other non serialized fields included in that CSV file.

What I want to do is have all those CSV files created in a gzip file … Here’s what I have so far! What happens it the user checks different check boxes with which file they want to export. Then its passed to this file where each file has a different SELECT query and field names. I haven’t even started to deal with the serialized data yet … I have no idea how I am going to do that. It then returns the CSV file and I place that file into an array which is waiting to be exported into a gzip … don’t even know if I can do that.

Any suggestions or help would be greatly appreciated!

$files = array();

if(in_array("general", $_POST['exportid'])){
 $files[] = CSVoutput("SELECT timestamp, id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, records, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 23, 24 FROM hourly", array(timestamp, id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, records, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 23, 24));
}

function CSVoutput($query, $fields){ 
 $rsSearchResults = mysql_query($query) or die(mysql_error());

 $out = '';
 $columns = count($fields);

 // Put the name of all fields
 for ($i = 0; $i < $columns; $i++) {
 $l= $fields[$i];
 $out .= '"'.$l.'",';
 }
 $out .="\n";

 // Add all values in the table
 while ($l = mysql_fetch_array($rsSearchResults)) {
 for ($i = 0; $i < $columns; $i++) {
 $out .='"'.$l["$i"].'",';
 }
 $out .="\n";
 }
 return $out;
 }
exit; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:21:42+00:00Added an answer on May 13, 2026 at 8:21 pm

    Check out the fputcsv() function. It will handle quotes/escaping much better than what you have.

    res = query_result
    row = fetch array from res
    
    handle/remove serialized columns in row
    fputcsv(row array keys)
    fputcsv(row values)
    
    while(row = fetch from res)
        handle/remove serialized columns in row
        fputcsv(row values)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer why not just showing a SELECT TOP 15 [name] ...?… May 16, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer Days of week are not bit flags. http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx The value… May 16, 2026 at 3:36 pm
  • Editorial Team
    Editorial Team added an answer If you're going to have that many entries and performance… May 16, 2026 at 3:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to create a csv export of data from mysql using the following
I'm writing a small sqlalchemy shim to export data from a MySQL database with
I am trying to do 2 output data from mysql to a csv file.
I have a CSV export script (enrdata_arch.php) which calls information from an existing database
I am trying to make an xml file to export my data from my
I'm trying to do a transition from MySQL to SQLite for a small site.
I am trying to connect to the database and get current state of a
I'm trying to export the results of a SQL statement via the SQL Server
I have been successful in querying a Microsoft Access 2003 database (.mdb file) and
I am trying to understand templates better I have a template class that starts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.