在php中创建csv文件时获取重复列

时间:2016-02-12 12:21:24

标签: 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文件概念是

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);
    }
}

当我提交帖子请求时,我收到带有重复列的csv文件

enter image description here

1 个答案:

答案 0 :(得分:2)

尝试

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