Creating Excel file from MySQL

后端 未结 5 616
死守一世寂寞
死守一世寂寞 2021-02-09 08:42

I am trying to generate an XLS file from a table in a MySQL DB, but the Excel file is not properly formatted & given error when the Excel file generated \"The file which you

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 08:59

    Sl No";
        for ( $i = 0; $i < $numcolumn; $i++ ) {
            $msg.="";
            $msg.= mysql_field_name($res, $i);  //will store column name of the table to msg variable
            $msg.="";
    
        }
        $msg.="";
        $i=0;
        $count=1; //used to print sl.no
        while($row=mysql_fetch_array($res))  //fetch all the row as array
        {
    
            $msg.="".$count."";
            for($i=0;$i< $numcolumn;$i++)
            {
                $var=$row[$i]; //will store all the values of row 
                $msg.="".$var."";
            }
            $count=$count+1;
            $msg.="";
        }
    
        $msg.="";
        echo $msg;  //will print the content in the exel page
    }
    ?>
    
    Click to download"; //link to download file
    ?>
    

提交回复
热议问题