Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created October 31, 2013 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongilbert/7258310 to your computer and use it in GitHub Desktop.
Save dongilbert/7258310 to your computer and use it in GitHub Desktop.
<?php
class SomeClass
{
public function resortCsv()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('robot_id, title, address1, city, state, zip, sub_title, description')
->from('#__rv_resorts');
$results = $db->setQuery($query)->loadObjectList();
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=ResortList.csv');
$output = fopen('php://output', 'w');
$headers = array('RobotID', 'Title', 'Address', 'City', 'State', 'Zip', 'Sub Title', 'Description');
fputcsv($output, $headers);
foreach ($results as $row)
{
$entry = array(
$row->robot_id,
$row->title,
$row->address1,
$row->city,
$row->state,
$row->zip,
$row->sub_title,
$row->description
);
fputcsv($output, $entry);
}
fclose($output);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment