douzhantao2857
2014-08-25 12:38
浏览 66
已采纳

使用php从mysql数据库导出csv文件

<?php
    include("includes/config.php"); 
    if ($_POST['frmCsv']) {
        $strSelect = doSelectCsv();
        header( 'Content-Type: text/csv' );
        header( 'Content-Disposition: attachment;filename=export.csv' );
        $strRow = mysql_fetch_assoc( $strSelect );
        printArray($strRow);
        if ( $strRow ) {
            outputcsv( array_keys( $strRow ) );
        }
        while ( $strRow ) {
            outputcsv( $strRow ); 
        }
    }

    function doSelectCsv()
    {
        $strSql = "SELECT * FROM tbl_member";
        $strResult = SelectQry($strSql);
    }

    function outputcsv( $fields )
    {
        $separator = '';
        foreach ( $fields as $field ) {
            echo $separator . $field;
            $separator = ',';     
        }
    }
?>

This is my code to export a csv file from the database. but it could not select the datas. select query did not works correctly. please help me.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题