I have this code and it exports mysql to csv already.
But it also export column names of the table.
I want to remove the names of the columns.
Which part should i remove or rewrite?
<?php
include('connection.php');
//header to give the order to the browser
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=exported-books.csv');
//select table to export the data
$select_table=mysql_query('select accessionnumber,datereceived,author,booktittle,bookcategory,format,callnumber,isbn,publisher,photo,barcodeid,times,addedby from books');
$rows = mysql_fetch_assoc($select_table);
if ($rows)
{
getcsv(array_keys($rows));
}
while($rows)
{
getcsv($rows);
$rows = mysql_fetch_assoc($select_table);
}
// get total number of fields present in the database
function getcsv($no_of_field_names)
{
$separate = '';
// do the action for all field names as field name
foreach ($no_of_field_names as $field_name)
{
if (preg_match('/\\r|\\n|,|"/', $field_name))
{
$field_name = '' . str_replace('', $field_name) . '';
}
echo $separate . $field_name;
//sepearte with the comma
$separate = ',';
}
//make new row and line
echo "\r\n";
}
?>
tia
$i = 0;
function getcsv($no_of_field_names) {
$separate = '';
foreach ($no_of_field_names as $field_name) {
if($i > 0) {
if (preg_match('/\\r|\\n|,|"/', $field_name)) {
$field_name = '' . str_replace('', $field_name) . '';
}
echo $separate . $field_name;
$separate = ',';
}
$i++;
}
//make new row and line
echo "\r\n";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.