Exclude DB Columns

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
clj83
Forum Members
Forum Members
Posts: 195
Joined: Tue Jul 07, 2009 4:09 pm

Exclude DB Columns

Post by clj83 »

Hi.

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,

Code: Select all

$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;
What I would like to do is also exclude the columns invhead_id and note from the rows output but so far all things I have tried have failed. Can anyone point me in the right direction?

Thanks
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Exclude DB Columns

Post by calguy1000 »

This is a general programming question, not related to CMSMS.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “Developers Discussion”