Right, so i have created a snippet as follows:
<?php
$output = '';//create variable for holding the output
$sql = $modx->db->query( 'SELECT * FROM `ebmonthlyweb_user_attributes_extended` LIMIT 0, 1000');//define the DB query, in this case the table is named 'tblprojects', add WHERE AND etc. as needed
$resultArray = $modx->db->makeArray( $sql );//put it into an array
foreach($resultArray as $item)//go through each record in the array
{//start looping through the data array
$params['gender']=$item['gender'];
$params['name']=$item['fullname'];
$params['businessname']=$item['username'];
$params['sector']=$item['business_type'];
$params['subscriber']=$item['subscriber'];//set the placeholders, the $params sets the name of the placeholder, the $item is the column name from the DB table
$params['address']=$item['address'];
$params['city']=$item['city'];
$params['county']=$item['state'];
$params['postcode']=$item['zip'];
$params['country']=$item['country'];
$params['phone']=$item['phone'];
$params['fax']=$item['fax'];
$params['email']=$item['email'];
$output.=$modx->parseChunk('databaseTpl', $params, '[+', '+]');//define the chunk name and process the content, here it's ProjectTpl which has the placeholders for the data
}//finish looping through the data array
return $output;//now return the output from the processed chunk
?>
I have a chunk called databaseTpl:
[+gender+],[+name+],[+sector+],[+subscriber+],[+address+],[+city+],[+county+],[+postcode+],[+country+],[+phone+],[+fax+],[+email+]<br/>
This displays a comma deliminated list of the contents of my required table.
But I need to be able to download this this list either as a plain txt file for importing into excel or as a CSV file.