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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:19:54+00:00 2026-06-14T13:19:54+00:00

Coming up empty on this one and could use some insight. I’m try to

  • 0

Coming up empty on this one and could use some insight.

I’m try to select only certain column_names (not column data) to set as a header for CSV file.

Right now, I can only pull all of the column names with
$result = mysql_query("SHOW COLUMNS FROM ".$table);

The problem is that it pulls all of the column names and I’m only wanting certain columns’ data. To get the data values this query is working perfectly:

$values = mysql_query("SELECT ".$columns." FROM ".$table." WHERE channel_id=26");

How do I select or show only the column names for the columns I list out in $columns, for example?

EDIT – I’m adding my full PHP here to provide more context. Line 7 is my problem.

<?php

$table = 'exp_channel_data'; // table we want to export
$columns = 'entry_id, field_id_26, field_id_27, '; // only the columns we want to show
$file = 'registrations-from-web'; // csv name.

$result = mysql_query("SHOW COLUMNS FROM ".$table);
$count = mysql_num_rows($result);

$csv_output = "";

if ($count > 0)
{
    while ($row = mysql_fetch_assoc($result))
    {
        $csv_output .= $row['Field'].", ";
    }
}

$csv_output .= "\n";
$values = mysql_query("SELECT ".$columns." FROM ".$table." WHERE channel_id=26");
while ($rowr = mysql_fetch_row($values))
{
    for ($j=0; $j<$count; $j++)
    {
        $csv_output .= $rowr[$j].", ";
    }

    $csv_output .= "\n";
}

$filename = $file."_".date("d-m-Y_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");

print $csv_output;

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-06-14T13:19:55+00:00Added an answer on June 14, 2026 at 1:19 pm

    I don’t know why I was missing this, but since I’m already having to list out the columns I need, I just needed to turn that string into an array to make is it work.

    $column_names = Array($columns);
    then later use
    $csv_output .= '"'.$rowr[$j].'",';

    That worked perfectly without redoing my entire code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched and searched and I'm coming up empty on this one guys. Help!
I've only just begun writing GUI programs, this being my second one. With both
I'm coming across this situation alot, I'll have a query that will have one
Coding footer naively, if there's not enough content, then there will be empty space
Coming from a .NET background I'm use to reusing string variables for storage, so
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
I've read every answer available for this question that I could find, including this
I'm wondering if anybody has run across something similar to this before. Some quick
This is my partial code of fileupload control page. This is the one I'm
I had a hard time coming up with a title for this question, but

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.