• Hello,

    I have written a custom plugin which will display some data from a particular table.
    Main Admin View of this plugin

    When I click on the ‘Export to CSV’ button the following window is opened

    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)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom CSV plugin [CSV Download Problem]’ is closed to new replies.