简体   繁体   中英

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. But I want to omit first column while writing to the csv file. 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. The id (which is not a graph point) will be included in csv file if I use a query like,

$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.?

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. Thanks..

Just UNSET it like

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

Orelse You can fetch all the columns except ID in your query itself like

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

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.

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