Title: Custom CSV plugin [CSV Download Problem]
Last modified: August 19, 2016

---

# Custom CSV plugin [CSV Download Problem]

 *  [yoursanjay](https://wordpress.org/support/users/yoursanjay/)
 * (@yoursanjay)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/custom-csv-plugin-csv-download-problem/)
 * Hello,
 * I have written a custom plugin which will display some data from a particular
   table.
    Main Admin View of this plugin [](http://content.screencast.com/users/esigners/folders/wp/media/4d4a41f8-6f0f-487f-bd8d-2f28f42b3260/csv1.jpg)
 * When I click on the ‘Export to CSV’ button the following window is opened
    [](http://content.screencast.com/users/esigners/folders/wp/media/7428479d-1ec2-4f63-b334-634f17a95052/csv2.jpg)
   rather not giving me any option to download the converted CSV file.
 * I need that when I click on the ‘Export to CSV’ button it give me the csv file
   to download my computer.
 * Here is the code section in the plugin for converting mysql data to CSV.
 *     ```
       // Get all the data from wp_newslette table
         $newsletter_result = mysql_query ("SELECT * FROM wp_newsletter WHERE newsletter = 1 ORDER BY nl_id DESC") or die (mysql_error());
   
         // Export all the data to CSV
         if ($_POST['submit'])
         {
           $out = '';
       	$fields = @mysql_list_fields('iwords','wp_newsletter');
       	$columns = @mysql_num_fields($fields);
   
       	// Put the name of all the fields
       	for ($i = 0; $i < $columns; $i++)
       	{
       	  $l=mysql_field_name($fields, $i);
       	  $out .= '"'.$l.'",';
       	}
       	$out .="\n";
   
       	// Add all the values in the table
       	while ($l = mysql_fetch_array($newsletter_result))
       	{
       	  for ($i = 0; $i < $columns; $i++)
       	  {
       	    $out .='"'.$l["$i"].'",';
       	  }
       	  $out .="\n";
       	}
       	@header("Content-type: text/x-csv");
       	@header("Content-Disposition: attachment; filename=filename.csv");
       	echo $out;
       	exit;
         }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [yoursanjay](https://wordpress.org/support/users/yoursanjay/)
 * (@yoursanjay)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/custom-csv-plugin-csv-download-problem/#post-1817423)
 * Sorry, I missed the screen shots.
    1st screen shot is [http://content.screencast.com/users/esigners/folders/wp/media/4d4a41f8-6f0f-487f-bd8d-2f28f42b3260/csv1.jpg](http://content.screencast.com/users/esigners/folders/wp/media/4d4a41f8-6f0f-487f-bd8d-2f28f42b3260/csv1.jpg)
 * 2nd screen shot is
    [http://content.screencast.com/users/esigners/folders/wp/media/7428479d-1ec2-4f63-b334-634f17a95052/csv2.jpg](http://content.screencast.com/users/esigners/folders/wp/media/7428479d-1ec2-4f63-b334-634f17a95052/csv2.jpg)

Viewing 1 replies (of 1 total)

The topic ‘Custom CSV plugin [CSV Download Problem]’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [yoursanjay](https://wordpress.org/support/users/yoursanjay/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/custom-csv-plugin-csv-download-problem/#post-1817423)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
