我在下面有这段代码,它的作用是从数据库中的数据生成一个 CSV,它工作正常。我唯一的问题是我想向 CSV 添加另一个字段(如果可能,在中间而不是最后)这可能吗?该字段将从数据中获取 DOB,并根据年龄给该人一个头衔(1994 年以后出生,他们是“初级”,然后是“高级”)等等,一个年龄可以有 4 或 5 个不同的头衔是。我希望这是有道理的。
function csv_all_members(){
$this->load->dbutil();
$this->db->select("first_name as 'First Name', last_name as 'Last Name', phone as 'Phone', os.group as 'Group', gender as 'Gender', birth_date as 'DOB', email as 'Email', street_address as 'Address', city as 'City', province as 'Province', postal_code as 'Postal Code', country 'Country', payment_amount as 'Payment Amount', DATE_FORMAT(payment_date, '%d/%m/%Y') as 'Payment Date', an.notes as 'Notes'", false);
$this->db->from('offline_shoppers os');
$this->db->join('athlete_notes an', 'os.id = an.id', 'inner');
$this->db->group_by(array("first_name", "last_name"));
$this->db->order_by("last_name asc, first_name asc");
$query = $this->db->get();
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=members_list.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo $this->dbutil->csv_from_result($query);
}