将SQL数据转换为excel [英] Convert SQL data to excel
本文介绍了将SQL数据转换为excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经按照youtube关于将MYSQL数据转换为excel的说明,顺便说一下,我已经尝试使用他们的数据库及其工作进行编码。但是当我用自己的数据库更改数据库中的数据库时,它不起作用
*我从youtube开始编码*
data.php
用户
>excel.php
<?php
$ connect = mysqli_connect(localhost,root,,test_db);
$ output ='';
if(isset($ _ POST [export_excel]))
{
$ sql =SELECT * FROM tbl_sample ORDER BY id DESC;
$ result = mysqli_query($ connect,$ sql);
if(mysqli_num_rows($ result)> 0)
{
$ output。='
< table class =tablebordered =1>
Id
名字
姓氏
';
while($ row = mysqli_fetch_array($ result))
{
$ output。='< br $>
'。$ row [id]。 '
'。$ row [first_name]。 '
'。$ row [last_name]。 '
';
}
$ output。='';
header(Content-Type:application / xls);
header(Content-Disposition:attachment; filename = download.xls);
echo $ output ;
}
}
我的尝试:
这是我改变的编码
data.php
用户
excel.php
<?php
$ connect = mysqli_connect(localhost,root,, 飞行);
$ output ='';
if(isset($ _ POST [export_excel]))
{
$ sql =SELECT * FROM customer ORDER BY id DESC;
$ result = mysqli_query($ connect,$ sql);
if(mysqli_num_rows($ result)> 10)
{
$ output。='
< table class =tablebordered =1>
>
';
while($ row = mysqli_fetch_array($ result))
{
$ output。='< br $>
';
}
$输出。='
Id | 客户名称 | 客户IC: | 客户状态: | < th>客户电子邮件客户地址 | ||
---|---|---|---|---|---|---|
'。$ row [id]。 | 。$行[ 客户id]。 | 。$行[ 客户名称]。 | 。$行[ CustomerNric]。 | 。$行[ 国家]。 | 。$行[ 电子邮件]。 | 。$行[ 地址。 ' |
header(Content-Type:application / xls);
header( Content-Disposition:attachment; filename = download.xls);
echo $ output;
}
}
I have follow instruction on youtube about converting MYSQL data to excel, btw I have try their coding with their database and its work. But when i change the database in that coding with my own database, its does not work
*This coding that i follow from youtube*
data.php
User
excel.php
<?php
$connect = mysqli_connect("localhost", "root", "", "test_db");
$output = '';
if(isset($_POST["export_excel"]))
{
$sql = "SELECT * FROM tbl_sample ORDER BY id DESC";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<table class="table" bordered="1"›
Id
First Name
Last Name
';
while($row = mysqli_fetch_array($result))
{
$output .= '
'.$row["id"]. '
'.$row["first_name"]. '
'.$row["last_name"]. '
';
}
$output .= '';
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=download.xls");
echo $output;
}
}
What I have tried:
This is coding that i change
data.php
User
excel.php
<?php
$connect = mysqli_connect("localhost", "root", "", "flight");
$output = '';
if(isset($_POST["export_excel"]))
{
$sql = "SELECT * FROM customer ORDER BY id DESC";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 10)
{
$output .= '
<table class="table" bordered="1"›
';
while($row = mysqli_fetch_array($result))
{
$output .= '
';
}
$output .= '
Id | Customer Name | Customer IC: | Customer State: | Customer Email | Customer Address | |
---|---|---|---|---|---|---|
'.$row["id"]. ' | '.$row["CustomerID"]. ' | '.$row["CustomerName"]. ' | '.$row["CustomerNric"]. ' | '.$row["State"]. ' | '.$row["Email"]. ' | '.$row["Address"]. ' |
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=download.xls");
echo $output;
}
}
推荐答案
connect = mysqli_connect(localhost,root,,test_db);
connect = mysqli_connect("localhost", "root", "", "test_db");
output ='';
if(isset(
output = '';
if(isset(
_POST [export_excel]) )
{
_POST["export_excel"]))
{
这篇关于将SQL数据转换为excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文