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 8180477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:13:23+00:00 2026-06-07T00:13:23+00:00

I am attempting to add a function that will create a csv for download

  • 0

I am attempting to add a function that will create a csv for download from a certain table in the db. I have got it partially working but cannot figure out how to exclude certain columns from the rows section of the csv. Here is my code so far,

$host = 'xxx';
$user = 'xxxx';
$pass = 'xxxx';
$db = 'xxxx';
$table = 'headers';
$file = 'export';

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");

$result = mysql_query("SHOW COLUMNS FROM ".$table." WHERE Field NOT IN ('invhead_id', 'note');");
$i = 0;
if (mysql_num_rows($result) > 0) 
{
   while ($row = mysql_fetch_assoc($result)) 
   {
      $csv_output .= $row['Field'].", ";
      $i++;
   }
}
$csv_output .= "\n";

$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) 
{
   for ($j=0;$j<$i;$j++) 
   {
      $csv_output .= $rowr[$j].", ";
   }

   $csv_output .= "\n";
}


print $csv_output;
exit;

I have excluded the columns invhead_id and note from the $result output but also need to exlude them from the $values output as well however this is the bit I cannot get to work. Can anyone point me in the right direction?

Thanks

  • 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-06-07T00:13:24+00:00Added an answer on June 7, 2026 at 12:13 am

    The easiest way is to select your columns by name instead of select *

    There is no easier way, but you could also write a php function that compares your two arrays and discards the ones you don’t want based on the first array and….you should just use my first idea.

    SELECT field1, field2, field7 FROM table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an export Excel/CSV function that will iterate through a custom
I'm attempting to create a function where I can pass names and values that
I'm attempting to add a bookmarklet to my wop website. The issue is that
I'm attempting to add a cmake build system to an old fortran code that
I am attempting to add a username to file path so I can create
I'm new to javascript and I am attempting to create an element with certain
I am working on a .NET 3.5 Windows Forms application that will interact with
I'm attempting the modify this Modx Snippet so that it will accept multiple values
Javascript is not my thing. I will leave it at that. I am attempting
So I am attempting to make a module that, when imported, will cause any

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.