Я узнаю о codeigniter, особенно об экспорте файла CSV, могу ли я создать CSV с объединением двух строк в столбец и установить значение в заголовке
Клиенты:
ID | CUSTOMER_NAME | TELP | EMAIL
1 | bobby | 698877 | bobby@gmail.com
2 | andrea | 778899 | andrea@gmail.com
Категории:
ID | CATERGORY_NAME | DESCRIPTION
1 | Food | anything about food
2 | Car | anything about car
Customer_category_relations:
ID | CUSTOMER_ID | CATEGORY_ID
1 | 1 | 1
2 | 2 | 2
Вопросы:
ID | CATEGORY_ID | QUESTION
1 | 1 | what your favorite food?
2 | 1 | which soda do you prefer?
3 | 2 | what sport car do you like?
4 | 2 | have you ever experiance nissan car?
Customer_answers:
ID | CUSTOMER_ID | QUESTION_ID | ANSWER
1 | 1 | 1 | burger
2 | 1 | 1 | salad
3 | 1 | 2 | cocacola
4 | 2 | 3 | mustang
5 | 2 | 3 | Lamborghini
6 | 2 | 4 | never
Я хочурезультат для CSV стал таким:
CUSTOMER_NAME | TELP | EMAIL | what your favorite food? | which soda do you prefer? | what sport car do you like? | have you ever experiance nissan car?
bobby | 698877 | bobby@gmail.com | burger, salad | cocacola | |
andrea | 778899 | andrea@gmail.com | | | mustang, Lamborghini | never
Как я могу создать CSV-файл с таким же результатом в codeigniter?или есть ли другие возможности?
до сих пор.я просто могу создать CSV, как это в контроллере
public function export_csv() {
$filename = "Export_".date("YmdH_i_s").".csv";
header('Content-type:text/csv');
header('Content-Disposition: attachment;filename='.$filename);
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0');
header('Pragma: no-cache');
header('Expires:0');
$handle = fopen('php://output','w');
fputcsv($handle, [
'customer_name',
'Telp',
'Email
]);
$res = $this->db->select('customer.customer_name,
customer.telp,
customer.email,
GROUP_CONCAT('customer_answers.answer) AS answer')
->from('customer')
->join('customer_category_relations', 'customer.id = customer_category_relations.customer_id', 'inner')
->join('categories', 'line_customer_questionnaire_relations.category_id = categories.id', 'INNER')
->join('questions', 'categories.id = questions.category_id', 'INNER')
->join('customer_answers', 'questions.id = customer_answers.question_id', 'INNER')
->group_by('customer_answers.question_id')
->get()
->result_array();
foreach ($res as $key => $value) {
fputcsv($handle, $value);
}
fclose($handle);
exit;
}
Что мне делать?