2014-12-10 2 views
1

이 코드는 이미 mysql을 csv로 내 보냅니다.열 이름 제거 (mysql을 CSV로 내보내기)

그러나 테이블의 열 이름도 내 보냅니다.

열 이름을 제거하고 싶습니다.

어떤 부분을 제거하거나 다시 작성해야합니까?

+0

<?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는 현재 반환하는 내용의 예를 표시합니다. – Mave

+0

accessionnumber, datereceived, author, booktittle, bookcategory, 형식, 전화 번호, isbn, 발행인, 사진, barcodeid, 시간, addedby 1,2014-12-10, saafv, qsadfsa, 기술, 응용 프로그램, Serial, 1241, sadfasf , sadgda, Blue hills.jpg, 2014-00000001,, 테이블 열도 마찬가지로 –

답변

0
$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"; 
} 
+0

부분을 대체해야합니까? nooby 죄송합니다 :( –

+0

난 기능 getcsv ($ no_of_field_names)에서 교체했지만 그것은 어떤 오류는 –

+0

에 오류 보여줍니다.?. 적어도 3 개의 매개 변수 – Mave