0

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

Community
  • 1
  • 1

1 Answers1

0

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'";
GautamD31
  • 28,552
  • 10
  • 64
  • 85