简体   繁体   English

使用fputcsv将mysql数据写入csv文件时省略一列

[英]Omit a column while writing mysql data into a csv file using fputcsv

My code for fetching mysql rows and write to csv file using fputscv is working fine. 我使用fputscv获取mysql行和写入csv文件的代码工作正常。 But I want to omit first column while writing to the csv file. 但是我想在写入csv文件时省略第一列。 Clearly telling, all the fetched values are different points of a graph and I would be directly importing that generated csv file for a graph generating code. 清楚地说,所有获取的值都是图形的不同点,我将直接导入生成的csv文件,用于生成代码的图形。 The id (which is not a graph point) will be included in csv file if I use a query like, 如果我使用像这样的查询,id(不是图形点)将包含在csv文件中,

$sql = "SELECT * FROM mybase WHERE id='$id'";
$qry = $dbo->prepare($sql);
$qry->execute();
$row = $qry->fetch(PDO::FETCH_ASSOC);       
fputcsv($data, $row);

Anyone knows the best method to eliminate the ID before writing into the csv file.? 在写入csv文件之前,任何人都知道消除ID的最佳方法。

I saw an obvious and simple result here . 我在这里看到了一个明显而简单的结果。 Unfortunately, I have too many columns and it is difficult to specify each column in sql query. 不幸的是,我有太多列,很难在sql查询中指定每一列。 Thanks.. 谢谢..

Just UNSET it like 就像UNSET一样

unset($row['ID']);
fputcsv($data, $row);

Orelse You can fetch all the columns except ID in your query itself like Orelse您可以在查询本身中获取除ID之外的所有列

$sql = "SELECT other_than_ID_column FROM mybase WHERE id='$id'";

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

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