Arif Khan
Arif Khan

Reputation: 63

getting duplicate column while creating csv file in php

    $stmt =$this->db->prepare("select * from abstract where account_name=:account_name");
    $stmt->bindparam(':account_name',$name);
    $stmt->execute();
    $getAccountInfo=$stmt->fetchAll();
    return $getAccountInfo;

csv file concept is

if (isset($_POST['xyz'])) {
    $randnum = rand(1111111111,9999999999);

    if (isset($data['0'])) {
        $fp= fopen("contacts_$randnum.csv","w");
        foreach ($data AS $values) {
            fputcsv($fp, $values);
        }
        fclose($fp);
    }
}

when i submit post request i am getting csv file with duplicate column

enter image description here

Upvotes: 2

Views: 127

Answers (1)

Batu.Khan
Batu.Khan

Reputation: 3065

Try

$getAccountInfo=$stmt->fetchAll(PDO::FETCH_ASSOC);

Upvotes: 2

Related Questions