我有這個查詢在這裏,這是我輸出它的方式csv,有人可以幫助我嗎? 這裏很麻煩,如果我將它打印爲Excel,並且我嘗試了一些版本,但是我使用odbc查詢的事實使它對我適應它與我找到的示例有點困難線上。問題與打印查詢爲csv
$result = "SELECT forma.*, SMS_MONTIME.IDTICKET,SMS_MONTIME.MBYLLUR,
SMS_MONTIME.time_added FROM forma
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE
forma.data_fillim >= '$df' AND forma.data_fillim <= '$dm' ORDER BY forma.id DESC";
$user_query = odbc_exec($connection, $result) or die(odbc_error());
//While loop to fetch the records
while($row = odbc_fetch_array($user_query))
{
$contents.=$row['klienti'].",";
$contents.=$row['id'].",";
$contents.=$row['tekniku_emer'].",";
$contents.=$row['telefoni'].",";
$contents.=$row['data_fillim'].",";
$contents.=$row['difekti'].",";
$contents.=$row['tekniku_mesazh'].",";
$contents.=$row['shenime'].",";
}
// remove html and php tags etc.
$contents = strip_tags($contents);
//header to make force download the file
header("Content-Disposition: attachment; filename=Kondicioner".date('d-m-Y').".csv");
print $contents;
除了這個事實,這將是一個容易得多,如果你使用PHP的內置[fputcsv()( http://www.php.net/manual/en/function.fputcsv.php)函數將每行寫入一個CSV文件行....您的問題到底是什麼? –
問題是,當我打開CSV沒有什麼是它的地方,行被搞砸了,他們沒有分開.. – Alb
你沒有在每行的末尾放回一個....使用fputcsv( ),你不必擔心這一點,或者從你的數據庫中檢索到的包含逗號的列,或者你沒有檢查的任何其他潛在的問題 –