Forums

CSV Export certain fields

andrewc 03 Nov, 2008
Hi

I would like to export only certain fields to CSV.
Don't want to export Chrono Forms id, IP etc.

Anyone know a hack?

in admin.chronocontact.php
I changed the below query to only the columns I wanted to export but it did not work. The CSV was blank..


function BackupCSV( $id, $option ) {
global $mosConfig_absolute_path, $database, $mosConfig_dbprefix;

	include_once $mosConfig_absolute_path.'/administrator/components/com_chronocontact/excelwriter/'."Writer.php";
	//echo $_POST['formid'];
	$database->setQuery( "SELECT name FROM #__chrono_contact WHERE id='".$_POST['formid'][0]."'" );
	$formname = $database->loadResult();
	
	$tablename = $mosConfig_dbprefix."chronoforms_".$_POST['formid'][0];
	$tables = array( $tablename );
 	$result = $database->getTableFields( $tables );
	$table_fields = array_keys($result[$tablename]);
	
	$database->setQuery( "SELECT * FROM ".$tablename."" );
	$datarows = $database->loadObjectList();
GreyHead 03 Nov, 2008
Hi andrewc,

I'd do this by creating a formlet to do the CSV export and avoid hacking the core code but I think this will make the change you want:
. . .
$table_fields = array_keys($result[$tablename]);
$skip_fields = array('cf_id', 'uid', 'recordtime', 'ipaddress');
$table_fields = array_diff($table_fields, $skip_fields);
. . .
Not tested and may well need debugging.

Bob
andrewc 03 Nov, 2008
Thanks bob!! works well.
This topic is locked and no more replies can be posted.