简体   繁体   English

删除列名(将mysql导出为CSV)

[英]Remove Column Name ( Export mysql to CSV )

I have this code and it exports mysql to csv already. 我有这段代码,它已经将mysql导出到csv。

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 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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM