Just post a form and get the data you need and write it, here is an example where I backup transactions to a csv file prior to purging:
public function checkPurge()
{
$stmt = $this->db->select("SELECT * FROM checks ORDER BY checkid", array(), \PDO::FETCH_ASSOC);
$k = 0;
$numbers[0] = 0;
$fileout = fopen("cleared.txt", "wb");
foreach ($stmt as $row) {
$k = $k + 1;
if ($k < 2) {
$checkid = $row['checkid'];
$transdate = $row['transdate'];
$transdrscribe = $row['transdescribe'];
$wd = Cln::fixInt($row['widthdraw']);
$dep = Cln::fixInt($row['deposit']);
$isclr = Cln::fixTiny($row['isclr']);
//$rs = Cln::fixInt($row['runsum']);
//echo "======k====" . $row['transdescribe'];
} else {
if ($row['isclr'] == 1) {
$checkid = $row['checkid'];
$transdate = $row['transdate'];
$transdrscribe = $row['transdescribe'];
$wd = Cln::fixInt($row['widthdraw']);
$dep = Cln::fixInt($row['deposit']);
$isclr = Cln::fixTiny($row['isclr']);
//$rs = Cln::fixInt($row['runsum']);
//echo "======k====" . $row['transdescribe'];
} else {
//$firstblank =
$k = 100000;
}
}
$newline = $checkid . " " . $transdate . " " . $transdrscribe . " " . $wd . " " . $dep . " " . $isclr . PHP_EOL;
$postdata = array(
'checkid' => $checkid,
'transdate' => $transdate,
'transdescribe' => $transdrscribe,
'widthdraw' => $wd,
'deposit' => $dep,
'isclr' => $isclr,
);
if ($k > 99999)
break;
fwrite($fileout, $newline);
$this->db->insert("checkbacks", $postdata);
/// more code